Changeset 3140 for trunk/src/kmk/read.c


Ignore:
Timestamp:
Mar 14, 2018, 10:28:10 PM (7 years ago)
Author:
bird
Message:

kmk: Merged in changes from GNU make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6 / https://git.savannah.gnu.org/git/make.git).

Location:
trunk/src/kmk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk

  • trunk/src/kmk/read.c

    r2857 r3140  
    11/* Reading and parsing of makefiles for GNU Make.
    2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
    4 2010 Free Software Foundation, Inc.
     2Copyright (C) 1988-2016 Free Software Foundation, Inc.
    53This file is part of GNU Make.
    64
     
    1715this program.  If not, see <http://www.gnu.org/licenses/>.  */
    1816
    19 #include "make.h"
     17#include "makeint.h"
    2018
    2119#include <assert.h>
    2220
    23 #include <glob.h>
    24 
     21#include "filedef.h"
    2522#include "dep.h"
    26 #include "filedef.h"
    2723#include "job.h"
    2824#include "commands.h"
     
    3531#endif
    3632
    37 #ifndef WINDOWS32
     33#ifdef WINDOWS32
     34#include <windows.h>
     35#include "sub_proc.h"
     36#else  /* !WINDOWS32 */
    3837#ifndef _AMIGA
    3938#ifndef VMS
     
    5958    unsigned int size;  /* Malloc'd size of buffer. */
    6059    FILE *fp;           /* File, or NULL if this is an internal buffer.  */
    61     struct floc floc;   /* Info on the file in fp (if any).  */
     60    floc floc;          /* Info on the file in fp (if any).  */
    6261  };
    6362
     
    8281
    8382
    84 /* A `struct conditionals' contains the information describing
     83/* A 'struct conditionals' contains the information describing
    8584   all the active conditionals in a makefile.
    8685
    87    The global variable `conditionals' contains the conditionals
     86   The global variable 'conditionals' contains the conditionals
    8887   information for the current makefile.  It is initialized from
    89    the static structure `toplevel_conditionals' and is later changed
     88   the static structure 'toplevel_conditionals' and is later changed
    9089   to new structures for included makefiles.  */
    9190
    9291struct conditionals
    9392  {
    94     unsigned int if_cmds;       /* Depth of conditional nesting.  */
    95     unsigned int allocated;     /* Elts allocated in following arrays.  */
    96     char *ignoring;             /* Are we ignoring or interpreting?
     93    unsigned int if_cmds;       /* Depth of conditional nesting.  */
     94    unsigned int allocated;     /* Elts allocated in following arrays.  */
     95    char *ignoring;             /* Are we ignoring or interpreting?
    9796                                   0=interpreting, 1=not yet interpreted,
    9897                                   2=already interpreted */
    99     char *seen_else;            /* Have we already seen an `else'?  */
     98    char *seen_else;            /* Have we already seen an 'else'?  */
    10099#ifdef KMK
    101100    char ignoring_first[8];
     
    154153   makefile currently being read in.  */
    155154
    156 const struct floc *reading_file = 0;
    157 
    158 /* The chain of makefiles read by read_makefile.  */
    159 
    160 static struct dep *read_makefiles = 0;
    161 
    162 static int eval_makefile (const char *filename, int flags);
     155const floc *reading_file = 0;
     156
     157/* The chain of files read by read_all_makefiles.  */
     158
     159static struct goaldep *read_files = 0;
     160
     161static struct goaldep *eval_makefile (const char *filename, int flags);
    163162static void eval (struct ebuffer *buffer, int flags);
    164163
     
    169168                                   enum variable_origin origin, struct ebuffer *ebuf);
    170169#ifndef CONFIG_WITH_VALUE_LENGTH
    171 static int conditional_line (char *line, int len, const struct floc *flocp);
    172 #else
    173 static int conditional_line (char *line, char *eol, int len, const struct floc *flocp);
     170static int conditional_line (char *line, int len, const floc *flocp);
     171#else
     172static int conditional_line (char *line, char *eol, int len, const floc *flocp);
    174173#endif
    175174static void record_files (struct nameseq *filenames, const char *pattern,
     
    177176                          unsigned int cmds_started, char *commands,
    178177                          unsigned int commands_idx, int two_colon,
    179                           const struct floc *flocp);
     178                          char prefix, const floc *flocp);
    180179static void record_target_var (struct nameseq *filenames, char *defn,
    181180                               enum variable_origin origin,
    182181                               struct vmodifiers *vmod,
    183                                const struct floc *flocp);
     182                               const floc *flocp);
    184183static enum make_word_type get_next_mword (char *buffer, char *delim,
    185184                                           char **startp, unsigned int *length);
    186185#ifndef CONFIG_WITH_VALUE_LENGTH
    187186static void remove_comments (char *line);
    188 static char *find_char_unquote (char *string, int stop1, int stop2,
    189                                 int blank, int ignorevars);
    190 #else  /* CONFIG_WITH_VALUE_LENGTH */
    191 __inline static char *remove_comments (char *line, char *eol);
    192 __inline static char *find_char_unquote_0 (char *string, int stop1, char **eosp);
    193 static char * find_char_unquote_2 (char *string, int stop1, int stop2,
    194                                    int blank, int ignorevars,
    195                                    unsigned int string_len);
    196 MY_INLINE char *
    197 find_char_unquote (char *string, int stop1, int stop2, int blank, int ignorevars)
    198 {
    199     if (!stop2 && !blank && !ignorevars)
    200       {
    201         char *p = strchr (string, stop1);
    202         if (!p)
    203           return NULL;
    204         if (p <= string || p[-1] != '\\')
    205           return p;
    206         /* fall back on find_char_unquote_2 */
    207       }
    208     return find_char_unquote_2 (string, stop1, stop2, blank, ignorevars, 0);
    209 }
     187static char *find_char_unquote (char *string, int map);
     188#else /* CONFIG_WITH_VALUE_LENGTH */
     189static char *remove_comments (char *line, char *eos);
     190static char *find_char_unquote (char *string, int map, unsigned int string_len);
     191K_INLINE char *find_char_unquote_0 (char *string, int stop1, int map, char **eosp);
    210192#endif /* CONFIG_WITH_VALUE_LENGTH */
     193static char *unescape_char (char *string, int c);
    211194
    212195
     
    214197   P must point to the word to be tested, and WLEN must be the length.
    215198*/
    216 #define word1eq(s)      (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
    217 
    218 
    219 
    220 /* Read in all the makefiles and return the chain of their names.  */
    221 
    222 struct dep *
     199#define word1eq(s)      (wlen == CSTRLEN (s) && strneq (s, p, CSTRLEN (s)))
     200
     201
     202
     203/* Read in all the makefiles and return a chain of targets to rebuild.  */
     204
     205struct goaldep *
    223206read_all_makefiles (const char **makefiles)
    224207{
     
    261244    while ((name = find_next_token ((const char **)&p, &length)) != 0)
    262245      {
    263         if (*p != '\0')
    264           *p++ = '\0';
    265         eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
     246        if (*p != '\0')
     247          *p++ = '\0';
     248        eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
    266249      }
    267250
     
    274257    while (*makefiles != 0)
    275258      {
    276         struct dep *tail = read_makefiles;
    277         register struct dep *d;
    278 
    279         if (! eval_makefile (*makefiles, 0))
    280           perror_with_name ("", *makefiles);
    281 
    282         /* Find the right element of read_makefiles.  */
    283         d = read_makefiles;
    284         while (d->next != tail)
    285           d = d->next;
    286 
    287         /* Use the storage read_makefile allocates.  */
    288         *makefiles = dep_name (d);
    289         ++num_makefiles;
    290         ++makefiles;
     259        struct goaldep *d = eval_makefile (*makefiles, 0);
     260
     261        if (errno)
     262          perror_with_name ("", *makefiles);
     263
     264        /* Reuse the storage allocated for the read_file.  */
     265        *makefiles = dep_name (d);
     266        ++num_makefiles;
     267        ++makefiles;
    291268      }
    292269
     
    295272  if (num_makefiles == 0)
    296273    {
    297       static char *default_makefiles[] =
     274      static const char *default_makefiles[] =
    298275#ifdef VMS
    299         /* all lower case since readdir() (the vms version) 'lowercasifies' */
     276        /* all lower case since readdir() (the vms version) 'lowercasifies' */
     277        /* TODO: Above is not always true, this needs more work */
    300278# ifdef KMK
    301         { "makefile.kmk", "makefile.vms", "gnumakefile.", "makefile.", 0 };
     279        { "makefile.kmk", "makefile.vms", "gnumakefile.", "makefile.", 0 };
    302280# else
    303         { "makefile.vms", "gnumakefile.", "makefile.", 0 };
     281        { "makefile.vms", "gnumakefile", "makefile", 0 };
    304282# endif
    305283#else
    306284#ifdef _AMIGA
    307         /* what's the deal here? no dots? */
    308285# ifdef KMK
    309         { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "Makefile", "SMakefile", 0 };
     286        { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "Makefile", "SMakefile", 0 };
    310287# else
    311         { "GNUmakefile", "Makefile", "SMakefile", 0 };
     288        { "GNUmakefile", "Makefile", "SMakefile", 0 };
    312289# endif
    313290#else /* !Amiga && !VMS */
     291#ifdef WINDOWS32
    314292# ifdef KMK
    315         { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "makefile", "Makefile", 0 };
     293        { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "makefile", "Makefile", "makefile.mak", 0 };
    316294# else
    317         { "GNUmakefile", "makefile", "Makefile", 0 };
     295        { "GNUmakefile", "makefile", "Makefile", "makefile.mak", 0 };
     296# endif       
     297#else /* !Amiga && !VMS && !WINDOWS32 */
     298# ifdef KMK
     299        { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "makefile", "Makefile", 0 };
     300# else
     301        { "GNUmakefile", "makefile", "Makefile", 0 };
    318302# endif
     303#endif /* !Amiga && !VMS && !WINDOWS32 */
    319304#endif /* AMIGA */
    320305#endif /* VMS */
    321       register char **p = default_makefiles;
     306      const char **p = default_makefiles;
    322307      while (*p != 0 && !file_exists_p (*p))
    323         ++p;
     308        ++p;
    324309
    325310      if (*p != 0)
    326         {
    327           if (! eval_makefile (*p, 0))
    328             perror_with_name ("", *p);
    329         }
     311        {
     312          eval_makefile (*p, 0);
     313          if (errno)
     314            perror_with_name ("", *p);
     315        }
    330316      else
    331         {
    332           /* No default makefile was found.  Add the default makefiles to the
    333              `read_makefiles' chain so they will be updated if possible.  */
    334           struct dep *tail = read_makefiles;
    335           /* Add them to the tail, after any MAKEFILES variable makefiles.  */
    336           while (tail != 0 && tail->next != 0)
    337             tail = tail->next;
    338           for (p = default_makefiles; *p != 0; ++p)
    339             {
    340               struct dep *d = alloc_dep ();
    341               d->file = enter_file (strcache_add (*p));
    342               d->dontcare = 1;
    343               /* Tell update_goal_chain to bail out as soon as this file is
    344                  made, and main not to die if we can't make this file.  */
    345               d->changed = RM_DONTCARE;
    346               if (tail == 0)
    347                 read_makefiles = d;
    348               else
    349                 tail->next = d;
    350               tail = d;
    351             }
    352           if (tail != 0)
    353             tail->next = 0;
    354         }
     317        {
     318          /* No default makefile was found.  Add the default makefiles to the
     319             'read_files' chain so they will be updated if possible.  */
     320          struct goaldep *tail = read_files;
     321          /* Add them to the tail, after any MAKEFILES variable makefiles.  */
     322          while (tail != 0 && tail->next != 0)
     323            tail = tail->next;
     324          for (p = default_makefiles; *p != 0; ++p)
     325            {
     326              struct goaldep *d = alloc_goaldep ();
     327              d->file = enter_file (strcache_add (*p));
     328              /* Tell update_goal_chain to bail out as soon as this file is
     329                 made, and main not to die if we can't make this file.  */
     330              d->flags = RM_DONTCARE;
     331              if (tail == 0)
     332                read_files = d;
     333              else
     334                tail->next = d;
     335              tail = d;
     336            }
     337          if (tail != 0)
     338            tail->next = 0;
     339        }
    355340    }
    356341
    357   return read_makefiles;
     342  return read_files;
    358343}
    359344
     
    386371  /* Free any space allocated by conditional_line.  */
    387372#ifdef KMK
    388   if (conditionals->allocated > sizeof (conditionals->ignoring_first))
    389 #endif
    390     {
    391       if (conditionals->ignoring)
    392         free (conditionals->ignoring);
    393       if (conditionals->seen_else)
    394         free (conditionals->seen_else);
    395     }
     373 if (conditionals->allocated > sizeof (conditionals->ignoring_first))
     374 {
     375#endif
     376  free (conditionals->ignoring);
     377  free (conditionals->seen_else);
     378#ifdef KMK
     379 }
     380#endif
    396381
    397382  /* Restore state.  */
     
    400385
    401386
    402 static int
     387static struct goaldep *
    403388eval_makefile (const char *filename, int flags)
    404389{
    405   struct dep *deps;
     390  struct goaldep *deps;
    406391  struct ebuffer ebuf;
    407   const struct floc *curfile;
     392  const floc *curfile;
    408393  char *expanded = 0;
    409394  int makefile_errno;
    410395
    411   filename = strcache_add (filename);
    412   ebuf.floc.filenm = filename;
     396  ebuf.floc.filenm = filename; /* Use the original file name.  */
    413397  ebuf.floc.lineno = 1;
     398  ebuf.floc.offset = 0;
    414399
    415400  if (ISDB (DB_VERBOSE))
    416401    {
    417       printf (_("Reading makefile `%s'"), filename);
     402      printf (_("Reading makefile '%s'"), filename);
    418403      if (flags & RM_NO_DEFAULT_GOAL)
    419         printf (_(" (no default goal)"));
     404        printf (_(" (no default goal)"));
    420405      if (flags & RM_INCLUDED)
    421         printf (_(" (search path)"));
     406        printf (_(" (search path)"));
    422407      if (flags & RM_DONTCARE)
    423         printf (_(" (don't care)"));
     408        printf (_(" (don't care)"));
    424409      if (flags & RM_NO_TILDE)
    425         printf (_(" (no ~ expansion)"));
     410        printf (_(" (no ~ expansion)"));
    426411      puts ("...");
    427412    }
     
    429414  /* First, get a stream to read.  */
    430415
    431   /* Expand ~ in FILENAME unless it came from `include',
     416  /* Expand ~ in FILENAME unless it came from 'include',
    432417     in which case it was already done.  */
    433418  if (!(flags & RM_NO_TILDE) && filename[0] == '~')
     
    435420      expanded = tilde_expand (filename);
    436421      if (expanded != 0)
    437         filename = expanded;
     422        filename = expanded;
    438423    }
    439424
    440   ebuf.fp = fopen (filename, "r");
     425  ENULLLOOP (ebuf.fp, fopen (filename, "r"));
     426
    441427  /* Save the error code so we print the right message later.  */
    442428  makefile_errno = errno;
    443429
     430  /* Check for unrecoverable errors: out of mem or FILE slots.  */
     431  switch (makefile_errno)
     432    {
     433#ifdef EMFILE
     434    case EMFILE:
     435#endif
     436#ifdef ENFILE
     437    case ENFILE:
     438#endif
     439    case ENOMEM:
     440      {
     441        const char *err = strerror (makefile_errno);
     442        OS (fatal, reading_file, "%s", err);
     443      }
     444    }
     445
    444446  /* If the makefile wasn't found and it's either a makefile from
    445      the `MAKEFILES' variable or an included makefile,
     447     the 'MAKEFILES' variable or an included makefile,
    446448     search the included makefile search path for this makefile.  */
    447449  if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/')
     
    449451      unsigned int i;
    450452      for (i = 0; include_directories[i] != 0; ++i)
    451         {
    452           const char *included = concat (3, include_directories[i],
     453        {
     454          const char *included = concat (3, include_directories[i],
    453455                                         "/", filename);
    454           ebuf.fp = fopen (included, "r");
    455           if (ebuf.fp)
    456             {
    457               filename = strcache_add (included);
    458               break;
    459             }
    460         }
     456          ebuf.fp = fopen (included, "r");
     457          if (ebuf.fp)
     458            {
     459              filename = included;
     460              break;
     461            }
     462        }
    461463    }
    462464
     465  /* Now we have the final name for this makefile. Enter it into
     466     the cache.  */
     467  filename = strcache_add (filename);
     468
    463469  /* Add FILENAME to the chain of read makefiles.  */
    464   deps = alloc_dep ();
    465   deps->next = read_makefiles;
    466   read_makefiles = deps;
     470  deps = alloc_goaldep ();
     471  deps->next = read_files;
     472  read_files = deps;
    467473#ifndef CONFIG_WITH_STRCACHE2
    468474  deps->file = lookup_file (filename);
     
    473479    deps->file = enter_file (filename);
    474480  filename = deps->file->name;
    475   deps->changed = flags;
    476   if (flags & RM_DONTCARE)
    477     deps->dontcare = 1;
    478 
    479   if (expanded)
    480     free (expanded);
     481  deps->flags = flags;
     482
     483  free (expanded);
    481484
    482485  /* If the makefile can't be found at all, give up entirely.  */
     
    485488    {
    486489      /* If we did some searching, errno has the error from the last
    487          attempt, rather from FILENAME itself.  Restore it in case the
    488         caller wants to use it in a message.  */
     490         attempt, rather from FILENAME itself.  Store it in case the
     491        caller wants to use it in a message.  */
    489492      errno = makefile_errno;
    490       return 0;
     493      return deps;
    491494    }
    492495
     
    576579  alloca (0);
    577580
    578   return 1;
     581  errno = 0;
     582  return deps;
    579583}
    580584
    581585void
    582 #ifndef CONFIG_WITH_VALUE_LENGTH
    583 eval_buffer (char *buffer)
    584 #else
    585 eval_buffer (char *buffer, char *eos)
    586 #endif
     586eval_buffer (char *buffer, const floc *flocp IF_WITH_VALUE_LENGTH_PARAM(char *eos))
    587587{
    588588  struct ebuffer ebuf;
    589589  struct conditionals *saved;
    590590  struct conditionals new;
    591   const struct floc *curfile;
     591  const floc *curfile;
    592592
    593593  /* Evaluate the buffer */
     
    603603  ebuf.fp = NULL;
    604604
    605   if (reading_file)
     605  if (flocp)
     606    ebuf.floc = *flocp;
     607  else if (reading_file)
    606608    ebuf.floc = *reading_file;
    607609  else
    608     ebuf.floc.filenm = NULL;
     610    {
     611      ebuf.floc.filenm = NULL;
     612      ebuf.floc.lineno = 1;
     613      ebuf.floc.offset = 0;
     614    }
    609615
    610616  curfile = reading_file;
     
    641647
    642648  /* Find the start of the next token.  If there isn't one we're done.  */
    643   line = next_token (line);
     649  NEXT_TOKEN (line);
    644650  if (*line == '\0')
    645651    return (char *)line;
     
    650656      int wlen;
    651657      const char *p2;
    652       enum variable_flavor flavor;
    653 
    654       p2 = parse_variable_definition (p, &flavor);
     658      struct variable v;
     659
     660      p2 = parse_variable_definition (p, &v);
    655661
    656662      /* If this is a variable assignment, we're done.  */
     
    713719  unsigned int cmds_started, tgts_started;
    714720  int ignoring = 0, in_ignored_define = 0;
    715   int no_targets = 0;           /* Set when reading a rule without targets.  */
     721  int no_targets = 0;           /* Set when reading a rule without targets.  */
    716722  struct nameseq *filenames = 0;
    717723  char *depstr = 0;
    718724  long nlines = 0;
    719725  int two_colon = 0;
     726  char prefix = cmd_prefix;
    720727  const char *pattern = 0;
    721728  const char *pattern_percent;
    722   struct floc *fstart;
    723   struct floc fi;
     729  floc *fstart;
     730  floc fi;
    724731#ifdef CONFIG_WITH_VALUE_LENGTH
    725732  unsigned int tmp_len;
     
    730737#endif
    731738
    732 #define record_waiting_files()                                                \
    733   do                                                                          \
    734     {                                                                         \
    735       if (filenames != 0)                                                     \
     739#define record_waiting_files()                                                \
     740  do                                                                          \
     741    {                                                                         \
     742      if (filenames != 0)                                                     \
    736743        {                                                                     \
    737           fi.lineno = tgts_started;                                           \
    738           record_files (filenames, pattern, pattern_percent, depstr,          \
     744          fi.lineno = tgts_started;                                           \
     745          fi.offset = 0;                                                      \
     746          record_files (filenames, pattern, pattern_percent, depstr,          \
    739747                        cmds_started, commands, commands_idx, two_colon,      \
    740                         &fi);                                                 \
    741           filenames = 0;                                                      \
     748                        prefix, &fi);                                         \
     749          filenames = 0;                                                      \
    742750        }                                                                     \
    743       commands_idx = 0;                                                       \
     751      commands_idx = 0;                                                       \
    744752      no_targets = 0;                                                         \
    745753      pattern = 0;                                                            \
     
    758766
    759767     When you see a "continue" in the loop below, that means we are moving on
    760      to the next line _without_ ending any rule that we happen to be working
    761      with at the moment.  If you see a "goto rule_complete", then the
    762      statement we just parsed also finishes the previous rule.  */
     768     to the next line.  If you see record_waiting_files(), then the statement
     769     we are parsing also finishes the previous rule.  */
    763770
    764771  commands = xmalloc (200);
     
    785792        break;
    786793
     794      line = ebuf->buffer;
     795
     796      /* If this is the first line, check for a UTF-8 BOM and skip it.  */
     797      if (ebuf->floc.lineno == 1 && line[0] == (char)0xEF
     798          && line[1] == (char)0xBB && line[2] == (char)0xBF)
     799        {
     800          line += 3;
     801          if (ISDB(DB_BASIC))
     802            {
     803              if (ebuf->floc.filenm)
     804                printf (_("Skipping UTF-8 BOM in makefile '%s'\n"),
     805                        ebuf->floc.filenm);
     806              else
     807                printf (_("Skipping UTF-8 BOM in makefile buffer\n"));
     808            }
     809        }
     810
    787811      /* If this line is empty, skip it.  */
    788       line = ebuf->buffer;
    789812      if (line[0] == '\0')
    790813        continue;
     
    798821
    799822      /* Check for a shell command line first.
    800          If it is not one, we can stop treating tab specially.  */
     823         If it is not one, we can stop treating cmd_prefix specially.  */
    801824      if (line[0] == cmd_prefix)
    802         {
    803           if (no_targets)
    804             /* Ignore the commands in a rule with no targets.  */
    805             continue;
    806 
    807           /* If there is no preceding rule line, don't treat this line
    808              as a command, even though it begins with a recipe prefix.
    809              SunOS 4 make appears to behave this way.  */
    810 
    811           if (filenames != 0)
    812             {
    813               if (ignoring)
    814                 /* Yep, this is a shell command, and we don't care.  */
    815                 continue;
    816 
    817               /* Append this command line to the line being accumulated.
    818                  Strip command prefix chars that appear after newlines.  */
    819               if (commands_idx == 0)
    820                 cmds_started = ebuf->floc.lineno;
    821 
    822               if (linelen + commands_idx > commands_len)
    823                 {
    824                   commands_len = (linelen + commands_idx) * 2;
    825                   commands = xrealloc (commands, commands_len);
    826                 }
    827               p = &commands[commands_idx];
    828               p2 = line + 1;
    829               while (--linelen)
     825        {
     826          if (no_targets)
     827            /* Ignore the commands in a rule with no targets.  */
     828            continue;
     829
     830          /* If there is no preceding rule line, don't treat this line
     831             as a command, even though it begins with a recipe prefix.
     832             SunOS 4 make appears to behave this way.  */
     833
     834          if (filenames != 0)
     835            {
     836              if (ignoring)
     837                /* Yep, this is a shell command, and we don't care.  */
     838                continue;
     839
     840              if (commands_idx == 0)
     841                cmds_started = ebuf->floc.lineno;
     842
     843              /* Append this command line to the line being accumulated.
     844                 Skip the initial command prefix character.  */
     845              if (linelen + commands_idx > commands_len)
    830846                {
    831                   ++commands_idx;
    832                   *(p++) = *p2;
    833                   if (p2[0] == '\n' && p2[1] == cmd_prefix)
    834                     {
    835                       ++p2;
    836                       --linelen;
    837                     }
    838                   ++p2;
     847                  commands_len = (linelen + commands_idx) * 2;
     848                  commands = xrealloc (commands, commands_len);
    839849                }
    840               *p = '\n';
    841               ++commands_idx;
    842 
    843               continue;
    844             }
    845         }
     850              memcpy (&commands[commands_idx], line + 1, linelen - 1);
     851              commands_idx += linelen - 1;
     852              commands[commands_idx++] = '\n';
     853              continue;
     854            }
     855        }
    846856
    847857      /* This line is not a shell command line.  Don't worry about whitespace.
     
    850860
    851861      if (collapsed_length < linelen+1)
    852         {
    853           collapsed_length = linelen+1;
    854           if (collapsed)
    855             free (collapsed);
     862        {
     863          collapsed_length = linelen+1;
     864          free (collapsed);
    856865          /* Don't need xrealloc: we don't need to preserve the content.  */
    857           collapsed = xmalloc (collapsed_length);
    858         }
     866          collapsed = xmalloc (collapsed_length);
     867        }
    859868#ifndef CONFIG_WITH_VALUE_LENGTH
    860869      strcpy (collapsed, line);
     
    873882      /* Get rid if starting space (including formfeed, vtab, etc.)  */
    874883      p = collapsed;
    875       while (isspace ((unsigned char)*p))
    876         ++p;
     884      NEXT_TOKEN (p);
    877885
    878886      /* See if this is a variable assignment.  We need to do this early, to
    879887         allow variables with names like 'ifdef', 'export', 'private', etc.  */
    880       p = parse_var_assignment(p, &vmod);
     888      p = parse_var_assignment (p, &vmod);
    881889      if (vmod.assign_v)
    882890        {
     
    885893
    886894          /* If we're ignoring then we're done now.  */
    887           if (ignoring)
     895          if (ignoring)
    888896            {
    889897              if (vmod.define_v)
     
    892900            }
    893901
     902          /* Variable assignment ends the previous rule.  */
     903          record_waiting_files ();
     904
    894905          if (vmod.undefine_v)
    895906          {
    896907            do_undefine (p, origin, ebuf);
    897 
    898             /* This line has been dealt with.  */
    899             goto rule_complete;
     908            continue;
    900909          }
    901910          else if (vmod.define_v)
     
    912921
    913922          /* This line has been dealt with.  */
    914           goto rule_complete;
     923          continue;
    915924        }
    916925
    917926      /* If this line is completely empty, ignore it.  */
    918927      if (*p == '\0')
    919         continue;
     928        continue;
    920929
    921930      p2 = end_of_token (p);
    922931      wlen = p2 - p;
    923       p2 = next_token (p2);
     932      NEXT_TOKEN (p2);
    924933
    925934      /* If we're in an ignored define, skip this line (but maybe get out).  */
    926935      if (in_ignored_define)
    927         {
     936        {
    928937          /* See if this is an endef line (plus optional comment).  */
    929           if (word1eq ("endef") && (*p2 == '\0' || *p2 == '#'))
     938          if (word1eq ("endef") && STOP_SET (*p2, MAP_COMMENT|MAP_NUL))
    930939            in_ignored_define = 0;
    931940
    932           continue;
    933         }
     941          continue;
     942        }
    934943
    935944      /* Check for conditional state changes.  */
     
    943952          {
    944953            if (i == -1)
    945               fatal (fstart, _("invalid syntax in conditional"));
     954              O (fatal, fstart, _("invalid syntax in conditional"));
    946955
    947956            ignoring = i;
     
    952961      /* Nothing to see here... move along.  */
    953962      if (ignoring)
    954         continue;
     963        continue;
    955964
    956965#ifdef CONFIG_WITH_LOCAL_VARIABLES
     
    958967        {
    959968          if (*p2 == '\0')
    960             error (fstart, _("empty `local' directive"));
     969            O (error, fstart, _("empty `local' directive"));
    961970
    962971          if (strneq (p2, "define", 6)
    963               && (isblank ((unsigned char)p2[6]) || p2[6] == '\0'))
     972              && (ISBLANK (p2[6]) || p2[6] == '\0'))
    964973            {
    965974              if (ignoring)
     
    969978                  p2 = next_token (p2 + 6);
    970979                  if (*p2 == '\0')
    971                     fatal (fstart, _("empty variable name"));
     980                    O (fatal, fstart, _("empty variable name"));
    972981
    973982                  /* Let the variable name be the whole rest of the line,
     
    976985                     reference that might contain blanks.  */
    977986                  p = strchr (p2, '\0');
    978                   while (isblank ((unsigned char)p[-1]))
     987                  while (ISBLANK (p[-1]))
    979988                    --p;
    980989                  do_define (p2 IF_WITH_VALUE_LENGTH_PARAM(p), o_local, ebuf);
     
    983992          else if (!ignoring
    984993                   && !try_variable_definition (fstart, p2 IF_WITH_VALUE_LENGTH_PARAM(eol), o_local, 0))
    985             error (fstart, _("invalid `local' directive"));
     994            O (error, fstart, _("invalid `local' directive"));
    986995
    987996          continue;
     
    9981007            {
    9991008              if (krc != 0)
    1000                 error (fstart, _("krc=%d"), krc);
     1009                ON (error, fstart, _("krc=%d"), krc);
    10011010              continue;
    10021011            }
     
    10071016         as well as "unexport".  */
    10081017      if (word1eq ("export") || word1eq ("unexport"))
    1009         {
     1018        {
    10101019          int exporting = *p == 'u' ? 0 : 1;
    10111020
     1021          /* Export/unexport ends the previous rule.  */
     1022          record_waiting_files ();
     1023
    10121024          /* (un)export by itself causes everything to be (un)exported. */
    1013           if (*p2 == '\0')
     1025          if (*p2 == '\0')
    10141026            export_all_variables = exporting;
    10151027          else
     
    10331045                  struct variable *v = lookup_variable (p, l);
    10341046                  if (v == 0)
    1035                     v = define_variable_loc (p, l, "", o_file, 0, fstart);
     1047                    v = define_variable_global (p, l, "", o_file, 0, fstart);
    10361048                  v->export = exporting ? v_export : v_noexport;
    10371049                }
     
    10431055#endif
    10441056            }
    1045           goto rule_complete;
    1046         }
     1057          continue;
     1058        }
    10471059
    10481060      /* Handle the special syntax for vpath.  */
    10491061      if (word1eq ("vpath"))
    1050         {
     1062        {
    10511063          const char *cp;
    1052           char *vpat;
    1053           unsigned int l;
    1054           cp = variable_expand (p2);
    1055           p = find_next_token (&cp, &l);
    1056           if (p != 0)
    1057             {
    1058               vpat = xstrndup (p, l);
    1059               p = find_next_token (&cp, &l);
    1060               /* No searchpath means remove all previous
    1061                  selective VPATH's with the same pattern.  */
    1062             }
    1063           else
    1064             /* No pattern means remove all previous selective VPATH's.  */
    1065             vpat = 0;
    1066           construct_vpath_list (vpat, p);
    1067           if (vpat != 0)
    1068             free (vpat);
    1069 
    1070           goto rule_complete;
    1071         }
     1064          char *vpat;
     1065          unsigned int l;
     1066
     1067          /* vpath ends the previous rule.  */
     1068          record_waiting_files ();
     1069
     1070          cp = variable_expand (p2);
     1071          p = find_next_token (&cp, &l);
     1072          if (p != 0)
     1073            {
     1074              vpat = xstrndup (p, l);
     1075              p = find_next_token (&cp, &l);
     1076              /* No searchpath means remove all previous
     1077                 selective VPATH's with the same pattern.  */
     1078            }
     1079          else
     1080            /* No pattern means remove all previous selective VPATH's.  */
     1081            vpat = 0;
     1082          construct_vpath_list (vpat, p);
     1083          free (vpat);
     1084
     1085          continue;
     1086        }
    10721087
    10731088#ifdef CONFIG_WITH_INCLUDEDEP
     
    10921107              free_me = name = allocated_variable_expand_3 (name, eol - name, &name_len, &buf_len);
    10931108              eol = name + name_len;
    1094               while (isspace ((unsigned char)*name))
     1109              while (ISSPACE (*name))
    10951110                ++name;
    10961111            }
    10971112
    1098           while (eol > name && isspace ((unsigned char)eol[-1]))
     1113          while (eol > name && ISSPACE (eol[-1]))
    10991114            --eol;
    11001115
     
    11041119          if (free_me)
    11051120            recycle_variable_buffer (free_me, buf_len);
    1106           goto rule_complete;
     1121          continue;
    11071122        }
    11081123#endif /* CONFIG_WITH_INCLUDEDEP */
     
    11101125      /* Handle include and variants.  */
    11111126      if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude"))
    1112         {
    1113           /* We have found an `include' line specifying a nested
    1114              makefile to be read at this point.  */
    1115           struct conditionals *save;
     1127        {
     1128          /* We have found an 'include' line specifying a nested
     1129             makefile to be read at this point.  */
     1130          struct conditionals *save;
    11161131          struct conditionals new_conditionals;
    1117           struct nameseq *files;
    1118           /* "-include" (vs "include") says no error if the file does not
    1119              exist.  "sinclude" is an alias for this from SGI.  */
    1120           int noerror = (p[0] != 'i');
     1132          struct nameseq *files;
     1133          /* "-include" (vs "include") says no error if the file does not
     1134             exist.  "sinclude" is an alias for this from SGI.  */
     1135          int noerror = (p[0] != 'i');
     1136#ifdef CONFIG_WITH_VALUE_LENGTH
     1137          unsigned int buf_len;
     1138#endif
     1139
     1140          /* Include ends the previous rule.  */
     1141          record_waiting_files ();
    11211142
    11221143#ifndef CONFIG_WITH_VALUE_LENGTH
    1123           p = allocated_variable_expand (p2);
    1124 #else
    1125           unsigned int buf_len;
     1144          p = allocated_variable_expand (p2);
     1145#else
    11261146          p = allocated_variable_expand_3 (p2, eol - p2, NULL, &buf_len);
    11271147#endif
    11281148
     1149
    11291150          /* If no filenames, it's a no-op.  */
    1130           if (*p == '\0')
     1151          if (*p == '\0')
    11311152            {
    11321153#ifndef CONFIG_WITH_VALUE_LENGTH
     
    11381159            }
    11391160
    1140           /* Parse the list of file names.  Don't expand archive references!  */
    1141           p2 = p;
    1142           files = PARSE_FILE_SEQ (&p2, struct nameseq, '\0', NULL,
     1161          /* Parse the list of file names.  Don't expand archive references!  */
     1162          p2 = p;
     1163          files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL,
    11431164                                  PARSEFS_NOAR);
    11441165#ifndef CONFIG_WITH_VALUE_LENGTH
    1145           free (p);
     1166          free (p);
    11461167#else
    11471168          recycle_variable_buffer (p, buf_len);
    11481169#endif
    11491170
    1150           /* Save the state of conditionals and start
    1151              the included makefile with a clean slate.  */
    1152           save = install_conditionals (&new_conditionals);
    1153 
    1154           /* Record the rules that are waiting so they will determine
    1155              the default goal before those in the included makefile.  */
    1156           record_waiting_files ();
    1157 
    1158           /* Read each included makefile.  */
    1159           while (files != 0)
    1160             {
    1161               struct nameseq *next = files->next;
    1162               const char *name = files->name;
     1171          /* Save the state of conditionals and start
     1172             the included makefile with a clean slate.  */
     1173          save = install_conditionals (&new_conditionals);
     1174
     1175          /* Record the rules that are waiting so they will determine
     1176             the default goal before those in the included makefile.  */
     1177          record_waiting_files ();
     1178
     1179          /* Read each included makefile.  */
     1180          while (files != 0)
     1181            {
     1182              struct nameseq *next = files->next;
     1183              int flags = (RM_INCLUDED | RM_NO_TILDE
     1184                           | (noerror ? RM_DONTCARE : 0)
     1185                           | (set_default ? 0 : RM_NO_DEFAULT_GOAL));
     1186
     1187              struct goaldep *d = eval_makefile (files->name, flags);
     1188
     1189              if (errno)
     1190                {
     1191                  d->error = (unsigned short)errno;
     1192                  d->floc = *fstart;
     1193                }
     1194
     1195              free_ns (files);
     1196              files = next;
     1197            }
     1198
     1199          /* Restore conditional state.  */
     1200          restore_conditionals (save);
     1201
     1202          continue;
     1203        }
     1204
     1205      /* Handle the load operations.  */
     1206      if (word1eq ("load") || word1eq ("-load"))
     1207        {
     1208          /* A 'load' line specifies a dynamic object to load.  */
     1209          struct nameseq *files;
     1210          int noerror = (p[0] == '-');
     1211
     1212          /* Load ends the previous rule.  */
     1213          record_waiting_files ();
     1214
     1215          p = allocated_variable_expand (p2);
     1216
     1217          /* If no filenames, it's a no-op.  */
     1218          if (*p == '\0')
     1219            {
     1220              free (p);
     1221              continue;
     1222            }
     1223
     1224          /* Parse the list of file names.
     1225             Don't expand archive references or strip "./"  */
     1226          p2 = p;
     1227          files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL,
     1228                                  PARSEFS_NOAR);
     1229          free (p);
     1230
     1231          /* Load each file.  */
     1232          while (files != 0)
     1233            {
     1234              struct nameseq *next = files->next;
     1235              const char *name = files->name;
     1236              struct goaldep *deps;
    11631237              int r;
    11641238
    1165               free_ns (files);
    1166               files = next;
    1167 
    1168               r = eval_makefile (name,
    1169                                  (RM_INCLUDED | RM_NO_TILDE
    1170                                   | (noerror ? RM_DONTCARE : 0)
    1171                                   | (set_default ? 0 : RM_NO_DEFAULT_GOAL)));
    1172               if (!r && !noerror)
    1173                 error (fstart, "%s: %s", name, strerror (errno));
    1174             }
    1175 
    1176           /* Restore conditional state.  */
    1177           restore_conditionals (save);
    1178 
    1179           goto rule_complete;
    1180         }
     1239              /* Load the file.  0 means failure.  */
     1240              r = load_file (&ebuf->floc, &name, noerror);
     1241              if (! r && ! noerror)
     1242                OS (fatal, &ebuf->floc, _("%s: failed to load"), name);
     1243
     1244              free_ns (files);
     1245              files = next;
     1246
     1247              /* Return of -1 means a special load: don't rebuild it.  */
     1248              if (r == -1)
     1249                continue;
     1250
     1251              /* It succeeded, so add it to the list "to be rebuilt".  */
     1252              deps = alloc_goaldep ();
     1253              deps->next = read_files;
     1254              read_files = deps;
     1255              deps->file = lookup_file (name);
     1256              if (deps->file == 0)
     1257                deps->file = enter_file (name);
     1258              deps->file->loaded = 1;
     1259            }
     1260
     1261          continue;
     1262        }
    11811263
    11821264      /* This line starts with a tab but was not caught above because there
     
    11841266         variable definition.  But now we know it is definitely lossage.  */
    11851267      if (line[0] == cmd_prefix)
    1186         fatal(fstart, _("recipe commences before first target"));
     1268        O (fatal, fstart, _("recipe commences before first target"));
    11871269
    11881270      /* This line describes some target files.  This is complicated by
    11891271         the existence of target-specific variables, because we can't
    11901272         expand the entire line until we know if we have one or not.  So
    1191          we expand the line word by word until we find the first `:',
     1273         we expand the line word by word until we find the first ':',
    11921274         then check to see if it's a target-specific variable.
    11931275
    1194          In this algorithm, `lb_next' will point to the beginning of the
    1195          unexpanded parts of the input buffer, while `p2' points to the
     1276         In this algorithm, 'lb_next' will point to the beginning of the
     1277         unexpanded parts of the input buffer, while 'p2' points to the
    11961278         parts of the expanded buffer we haven't searched yet. */
    11971279
     
    12101292        /* Search the line for an unquoted ; that is not after an
    12111293           unquoted #.  */
    1212 #ifndef CONFIG_WITH_VALUE_LENGTH
    1213         cmdleft = find_char_unquote (line, ';', '#', 0, 1);
    1214 #else
    1215         cmdleft = find_char_unquote_2 (line, ';', '#', 0, 1, ebuf->eol - line);
    1216 #endif
     1294        cmdleft = find_char_unquote (line, MAP_SEMI|MAP_COMMENT|MAP_VARIABLE IF_WITH_VALUE_LENGTH_PARAM(ebuf->eol - line));
    12171295        if (cmdleft != 0 && *cmdleft == '#')
    12181296          {
     
    12361314           beginning, expanding as we go, and looking for "interesting"
    12371315           chars.  The first word is always expandable.  */
    1238         wtype = get_next_mword(line, NULL, &lb_next, &wlen);
     1316        wtype = get_next_mword (line, NULL, &lb_next, &wlen);
    12391317        switch (wtype)
    12401318          {
    12411319          case w_eol:
    12421320            if (cmdleft != 0)
    1243               fatal(fstart, _("missing rule before recipe"));
     1321              O (fatal, fstart, _("missing rule before recipe"));
    12441322            /* This line contained something but turned out to be nothing
    12451323               but whitespace (a comment?).  */
     
    12571335          }
    12581336
    1259 
    12601337#ifndef CONFIG_WITH_VALUE_LENGTH
    1261         p2 = variable_expand_string(NULL, lb_next, wlen);
     1338        p2 = variable_expand_string (NULL, lb_next, wlen);
    12621339#else
    12631340        p2 = variable_expand_string_2 (NULL, lb_next, wlen, &eol);
     
    12721349                /* Look for a semicolon in the expanded line.  */
    12731350#ifndef CONFIG_WITH_VALUE_LENGTH
    1274                 cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
    1275 #else
    1276                 cmdleft = find_char_unquote_0 (p2, ';', &eol);
     1351                cmdleft = find_char_unquote (p2, MAP_SEMI);
     1352#else
     1353                cmdleft = find_char_unquote_0 (p2, ';', MAP_SEMI, &eol);
    12771354#endif
    12781355
     
    12821359                    unsigned long cmd_off = cmdleft - variable_buffer;
    12831360#ifndef CONFIG_WITH_VALUE_LENGTH
    1284                     char *pend = p2 + strlen(p2);
     1361                    char *pend = p2 + strlen (p2);
    12851362#endif
    12861363
     
    12931370                       and into a command script.  However, the old parser
    12941371                       expanded the whole line, so we continue that for
    1295                        backwards-compatiblity.  Also, it wouldn't be
     1372                       backwards-compatibility.  Also, it wouldn't be
    12961373                       entirely consistent, since we do an unconditional
    12971374                       expand below once we know we don't have a
    12981375                       target-specific variable. */
    12991376#ifndef CONFIG_WITH_VALUE_LENGTH
    1300                     (void)variable_expand_string(pend, lb_next, (long)-1);
    1301                     lb_next += strlen(lb_next);
     1377                    (void)variable_expand_string (pend, lb_next, (long)-1);
     1378                    lb_next += strlen (lb_next);
    13021379#else
    13031380                    tmp_len = strlen (lb_next);
     
    13111388
    13121389#ifndef CONFIG_WITH_VALUE_LENGTH
    1313             colonp = find_char_unquote(p2, ':', 0, 0, 0);
    1314 #else
    1315             colonp = find_char_unquote_0 (p2, ':', &eol);
     1390            colonp = find_char_unquote (p2, MAP_COLON);
     1391#else
     1392            colonp = find_char_unquote_0 (p2, ':', MAP_COLON, &eol);
    13161393#endif
    13171394#ifdef HAVE_DOS_PATHS
     
    13241401                   (colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0))
    13251402# ifndef CONFIG_WITH_VALUE_LENGTH
    1326               colonp = find_char_unquote(colonp + 1, ':', 0, 0, 0);
     1403              colonp = find_char_unquote (colonp + 1, MAP_COLON);
    13271404# else
    1328               colonp = find_char_unquote_0 (colonp + 1, ':', &eol);
     1405              colonp = find_char_unquote_0 (colonp + 1, ':', MAP_COLON, &eol);
    13291406# endif
    13301407#endif
     
    13321409              break;
    13331410
    1334             wtype = get_next_mword(lb_next, NULL, &lb_next, &wlen);
     1411            wtype = get_next_mword (lb_next, NULL, &lb_next, &wlen);
    13351412            if (wtype == w_eol)
    13361413              break;
    13371414
    13381415#ifndef CONFIG_WITH_VALUE_LENGTH
    1339             p2 += strlen(p2);
     1416            p2 += strlen (p2);
    13401417            *(p2++) = ' ';
    1341             p2 = variable_expand_string(p2, lb_next, wlen);
     1418            p2 = variable_expand_string (p2, lb_next, wlen);
    13421419#else
    13431420            *(eol++) = ' ';
     
    13561433        if (wtype == w_eol)
    13571434          {
    1358             if (*p2 != '\0')
    1359               /* There's no need to be ivory-tower about this: check for
    1360                  one of the most common bugs found in makefiles...  */
    1361               fatal (fstart, _("missing separator%s"),
    1362                      (cmd_prefix == '\t' && !strneq(line, "        ", 8))
    1363                      ? "" : _(" (did you mean TAB instead of 8 spaces?)"));
    1364             continue;
     1435            if (*p2 == '\0')
     1436              continue;
     1437
     1438            /* There's no need to be ivory-tower about this: check for
     1439               one of the most common bugs found in makefiles...  */
     1440            if (cmd_prefix == '\t' && strneq (line, "        ", 8))
     1441              O (fatal, fstart, _("missing separator (did you mean TAB instead of 8 spaces?)"));
     1442            else
     1443              O (fatal, fstart, _("missing separator"));
    13651444          }
    13661445
    13671446        /* Make the colon the end-of-string so we know where to stop
    1368            looking for targets.  */
     1447           looking for targets.  Start there again once we're done.  */
    13691448        *colonp = '\0';
    1370         filenames = PARSE_FILE_SEQ (&p2, struct nameseq, '\0', NULL, 0);
    1371         *p2 = ':';
     1449        filenames = PARSE_SIMPLE_SEQ (&p2, struct nameseq);
     1450        *colonp = ':';
     1451        p2 = colonp;
    13721452
    13731453        if (!filenames)
     
    14061486            if (semip)
    14071487              {
    1408                 unsigned int l = p - variable_buffer;
     1488                unsigned int l = p2 - variable_buffer;
    14091489                *(--semip) = ';';
    14101490#ifndef CONFIG_WITH_VALUE_LENGTH
     
    14151495                variable_buffer_output (p2 + strlen (p2),
    14161496                                        semip, strlen (semip)+1);
    1417                 p = variable_buffer + l;
     1497                p2 = variable_buffer + l;
    14181498              }
    14191499            record_target_var (filenames, p2,
     
    14261506        /* This is a normal target, _not_ a target-specific variable.
    14271507           Unquote any = in the dependency list.  */
    1428         find_char_unquote (lb_next, '=', 0, 0, 0);
     1508#ifndef CONFIG_WITH_VALUE_LENGTH
     1509        find_char_unquote (lb_next, MAP_EQUALS);
     1510#else
     1511        {
     1512          char *tmp_eos = strchr(lb_next, '\0'); /** @todo see if we can optimize this away... */
     1513          find_char_unquote_0 (lb_next, '=', MAP_EQUALS, &tmp_eos);
     1514        }
     1515#endif
     1516
     1517        /* Remember the command prefix for this target.  */
     1518        prefix = cmd_prefix;
    14291519
    14301520        /* We have some targets, so don't ignore the following commands.  */
     
    14471537              {
    14481538#ifndef CONFIG_WITH_VALUE_LENGTH
    1449                 cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
    1450 #else
    1451                 cmdleft = find_char_unquote_0 (p2, ';', &eos);
     1539                cmdleft = find_char_unquote (p2, MAP_SEMI);
     1540#else
     1541                cmdleft = find_char_unquote_0 (p2, ';', MAP_SEMI, &eos);
    14521542#endif
    14531543                if (cmdleft != 0)
     
    14561546          }
    14571547
    1458         /* Is this a static pattern rule: `target: %targ: %dep; ...'?  */
     1548        /* Is this a static pattern rule: 'target: %targ: %dep; ...'?  */
    14591549        p = strchr (p2, ':');
    14601550        while (p != 0 && p[-1] == '\\')
     
    14821572           OR a space around the :.
    14831573        */
    1484         if (p && !(isspace ((unsigned char)p[1]) || !p[1]
    1485                    || isspace ((unsigned char)p[-1])))
     1574        if (p && !(ISSPACE (p[1]) || !p[1] || ISSPACE (p[-1])))
    14861575          p = 0;
    14871576#endif
     
    15041593          {
    15051594            struct nameseq *target;
    1506             target = PARSE_FILE_SEQ (&p2, struct nameseq, ':', NULL,
     1595            target = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_COLON, NULL,
    15071596                                     PARSEFS_NOGLOB);
    15081597            ++p2;
    15091598            if (target == 0)
    1510               fatal (fstart, _("missing target pattern"));
     1599              O (fatal, fstart, _("missing target pattern"));
    15111600            else if (target->next != 0)
    1512               fatal (fstart, _("multiple target patterns (target `%s')"), target->name); /* bird */
     1601              OS (fatal, fstart, _("multiple target patterns (target '%s')"), target->name); /* bird added target */
    15131602            pattern_percent = find_percent_cached (&target->name);
    15141603            pattern = target->name;
    15151604            if (pattern_percent == 0)
    1516               fatal (fstart, _("target pattern contains no `%%' (target `%s')"), target->name); /* bird */
     1605              OS (fatal, fstart, _("target pattern contains no '%%' (target '%s')"), target->name); /* bird added target */
    15171606            free_ns (target);
    15181607          }
     
    15671656        if (set_default && default_goal_var->value[0] == '\0')
    15681657          {
    1569             const char *name;
    15701658            struct dep *d;
    15711659            struct nameseq *t = filenames;
     
    15741662              {
    15751663                int reject = 0;
    1576                 name = t->name;
     1664                const char *name = t->name;
    15771665
    15781666                /* We have nothing to do if this is an implicit rule. */
     
    15801668                  break;
    15811669
    1582                 /* See if this target's name does not start with a `.',
     1670                /* See if this target's name does not start with a '.',
    15831671                   unless it contains a slash.  */
    15841672                if (*name == '.' && strchr (name, '/') == 0
     
    16331721
    16341722      /* We get here except in the case that we just read a rule line.
    1635          Record now the last rule we read, so following spurious
    1636          commands are properly diagnosed.  */
    1637  rule_complete:
     1723         Record now the last rule we read, so following spurious
     1724         commands are properly diagnosed.  */
    16381725      record_waiting_files ();
    16391726    }
    16401727
    1641 #undef  word1eq
     1728#undef word1eq
    16421729
    16431730  if (conditionals->if_cmds)
    1644     fatal (fstart, _("missing `endif'"));
     1731    O (fatal, fstart, _("missing 'endif'"));
    16451732#ifdef KMK
    16461733
    16471734  if (kdata != NULL)
    1648     fatal (fstart, _("missing `kBuild-endef-*'"));
     1735    O (fatal, fstart, _("missing `kBuild-endef-*'"));
    16491736#endif
    16501737
     
    16521739  record_waiting_files ();
    16531740
    1654   if (collapsed)
    1655     free (collapsed);
     1741  free (collapsed);
    16561742  free (commands);
    16571743}
     
    16651751static void
    16661752remove_comments (char *line)
     1753#else
     1754static char *
     1755remove_comments (char *line, char *eos)
     1756#endif
    16671757{
    16681758  char *comment;
    16691759
    1670   comment = find_char_unquote (line, '#', 0, 0, 0);
     1760#ifndef CONFIG_WITH_VALUE_LENGTH
     1761  comment = find_char_unquote (line, MAP_COMMENT);
    16711762
    16721763  if (comment != 0)
    16731764    /* Cut off the line at the #.  */
    16741765    *comment = '\0';
     1766#else
     1767  comment = find_char_unquote_0 (line, '#', MAP_COMMENT, &eos);
     1768  if (comment)
     1769    {
     1770      /* Cut off the line at the #.  */
     1771      *comment = '\0';
     1772      return comment;
     1773    }
     1774  return eos;
     1775#endif
    16751776}
    1676 #else  /* CONFIG_WITH_VALUE_LENGTH */
    1677 __inline static char *
    1678 remove_comments (char *line, char *eol)
    1679 {
    1680   unsigned int string_len = eol - line;
    1681   register int ch;
    1682   char *p;
    1683 
    1684   /* Hope for simple (no comments). */
    1685   p = memchr (line, '#', string_len);
    1686   if (!p)
    1687     return eol;
    1688 
    1689   /* Found potential comment, enter the slow route. */
    1690   for (;;)
    1691     {
    1692       if (p > line && p[-1] == '\\')
    1693         {
    1694           /* Search for more backslashes.  */
    1695           int i = -2;
    1696           while (&p[i] >= line && p[i] == '\\')
    1697             --i;
    1698           ++i;
    1699 
    1700           /* The number of backslashes is now -I.
    1701              Copy P over itself to swallow half of them.  */
    1702           memmove (&p[i], &p[i/2], (string_len - (p - line)) - (i/2) + 1);
    1703           p += i/2;
    1704           if (i % 2 == 0)
    1705             {
    1706               /* All the backslashes quoted each other; the STOPCHAR was
    1707                  unquoted.  */
    1708               *p = '\0';
    1709               return p;
    1710             }
    1711 
    1712           /* The '#' was quoted by a backslash.  Look for another.  */
    1713         }
    1714       else
    1715         {
    1716           /* No backslash in sight.  */
    1717           *p = '\0';
    1718           return p;
    1719         }
    1720 
    1721       /* lazy, string_len isn't correct so do it the slow way. */
    1722       while ((ch = *p) != '#')
    1723         {
    1724           if (ch == '\0')
    1725             return p;
    1726           ++p;
    1727         }
    1728     }
    1729   /* won't ever get here. */
    1730 }
    1731 #endif /* CONFIG_WITH_VALUE_LENGTH */
    1732 
    1733 /* Execute a `undefine' directive.
     1777
     1778/* Execute a 'undefine' directive.
    17341779   The undefine line has already been read, and NAME is the name of
    17351780   the variable to be undefined. */
     
    17441789  name = next_token (var);
    17451790  if (*name == '\0')
    1746     fatal (&ebuf->floc, _("empty variable name"));
     1791    O (fatal, &ebuf->floc, _("empty variable name"));
    17471792  p = name + strlen (name) - 1;
    1748   while (p > name && isblank ((unsigned char)*p))
     1793  while (p > name && ISBLANK (*p))
    17491794    --p;
    17501795  p[1] = '\0';
     
    17541799}
    17551800
    1756 /* Execute a `define' directive.
     1801/* Execute a 'define' directive.
    17571802   The first line has already been read, and NAME is the name of
    17581803   the variable to be defined.  The following lines remain to be read.  */
     
    17631808{
    17641809  struct variable *v;
    1765   enum variable_flavor flavor;
    1766   struct floc defstart;
     1810  struct variable var;
     1811  floc defstart;
    17671812  int nlevels = 1;
    17681813  unsigned int length = 100;
    17691814  char *definition = xmalloc (length);
    17701815  unsigned int idx = 0;
    1771   char *p, *var;
     1816  char *p, *n;
    17721817
    17731818  defstart = ebuf->floc;
    17741819
    1775   p = parse_variable_definition (name, &flavor);
     1820  p = parse_variable_definition (name, &var);
    17761821  if (p == NULL)
    17771822    /* No assignment token, so assume recursive.  */
    1778     flavor = f_recursive;
     1823    var.flavor = f_recursive;
    17791824  else
    17801825    {
    1781       if (*(next_token (p)) != '\0')
    1782         error (&defstart, _("extraneous text after `define' directive"));
     1826      if (var.value[0] != '\0')
     1827        O (error, &defstart, _("extraneous text after 'define' directive"));
    17831828
    17841829      /* Chop the string before the assignment token to get the name.  */
    1785       p[flavor == f_recursive ? -1 : -2] = '\0';
     1830#ifndef CONFIG_WITH_STRCACHE2
     1831      var.name[var.length] = '\0';
     1832#else
     1833      assert (!strcache2_is_cached (&variable_strcache, var.name));
     1834      ((char *)var.name)[var.length] = '\0';
     1835#endif
    17861836    }
    17871837
    17881838  /* Expand the variable name and find the beginning (NAME) and end.  */
    1789   var = allocated_variable_expand (name);
    1790   name = next_token (var);
    1791   if (*name == '\0')
    1792     fatal (&defstart, _("empty variable name"));
     1839  n = allocated_variable_expand (name);
     1840  name = next_token (n);
     1841  if (name[0] == '\0')
     1842    O (fatal, &defstart, _("empty variable name"));
    17931843  p = name + strlen (name) - 1;
    1794   while (p > name && isblank ((unsigned char)*p))
     1844  while (p > name && ISBLANK (*p))
    17951845    --p;
    17961846  p[1] = '\0';
     
    18051855      /* If there is nothing left to be eval'd, there's no 'endef'!!  */
    18061856      if (nlines < 0)
    1807         fatal (&defstart, _("missing `endef', unterminated `define'"));
     1857        O (fatal, &defstart, _("missing 'endef', unterminated 'define'"));
    18081858
    18091859      ebuf->floc.lineno += nlines;
     
    18291879
    18301880          /* If this is another 'define', increment the level count.  */
    1831           if ((len == 6 || (len > 6 && isblank ((unsigned char)p[6])))
     1881          if ((len == 6 || (len > 6 && ISBLANK (p[6])))
    18321882              && strneq (p, "define", 6))
    18331883            ++nlevels;
     
    18351885          /* If this is an 'endef', decrement the count.  If it's now 0,
    18361886             we've found the last one.  */
    1837           else if ((len == 5 || (len > 5 && isblank ((unsigned char)p[5])))
     1887          else if ((len == 5 || (len > 5 && ISBLANK (p[5])))
    18381888                   && strneq (p, "endef", 5))
    18391889            {
     
    18451895#endif
    18461896              if (*(next_token (p)) != '\0')
    1847                 error (&ebuf->floc,
    1848                        _("extraneous text after `endef' directive"));
     1897                O (error, &ebuf->floc,
     1898                   _("extraneous text after 'endef' directive"));
    18491899
    18501900              if (--nlevels == 0)
     
    18791929
    18801930#ifndef CONFIG_WITH_VALUE_LENGTH
    1881   v = do_variable_definition (&defstart, name, definition, origin, flavor, 0);
     1931  v = do_variable_definition (&defstart, name,
     1932                              definition, origin, var.flavor, 0);
    18821933#else
    18831934  v = do_variable_definition_2 (&defstart, name, definition,
    1884                                 idx ? idx - 1 : idx,  flavor == f_simple,
    1885                                 0 /* free_value */, origin, flavor,
     1935                                idx ? idx - 1 : idx,  var.flavor == f_simple,
     1936                                0 /* free_value */, origin, var.flavor,
    18861937                                0 /*target_var*/);
    18871938#endif
    18881939  free (definition);
    1889   free (var);
     1940  free (n);
    18901941  return (v);
    18911942}
     
    19051956
    19061957static int
    1907 #ifndef CONFIG_WITH_VALUE_LENGTH
    1908 conditional_line (char *line, int len, const struct floc *flocp)
    1909 #else
    1910 conditional_line (char *line, char *eol, int len, const struct floc *flocp)
    1911 #endif
     1958conditional_line (char *line IF_WITH_VALUE_LENGTH_PARAM(char *eol), int len, const floc *flocp)
    19121959{
    1913   char *cmdname;
     1960  const char *cmdname;
    19141961  enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq,
    19151962#ifdef CONFIG_WITH_SET_CONDITIONALS
     
    19281975
    19291976  /* Compare a word, both length and contents. */
    1930 #define word1eq(s)      (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))
    1931 #define chkword(s, t)   if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
     1977#define word1eq(s)      (len == CSTRLEN (s) && strneq (s, line, CSTRLEN (s)))
     1978#define chkword(s, t)   if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
    19321979
    19331980  /* Make sure this line is a conditional.  */
     
    19491996
    19501997  /* Found one: skip past it and any whitespace after it.  */
    1951   line = next_token (line + len);
    1952 
    1953 #define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname)
     1998  line += len;
     1999  NEXT_TOKEN (line);
     2000
     2001#define EXTRATEXT() OS (error, flocp, _("extraneous text after '%s' directive"), cmdname)
     2002#define EXTRACMD()  OS (fatal, flocp, _("extraneous '%s'"), cmdname)
    19542003
    19552004  /* An 'endif' cannot contain extra text, and reduces the if-depth by 1  */
     
    19572006    {
    19582007      if (*line != '\0')
    1959         EXTRANEOUS ();
     2008        EXTRATEXT ();
    19602009
    19612010      if (!conditionals->if_cmds)
    1962         fatal (flocp, _("extraneous `%s'"), cmdname);
     2011        EXTRACMD ();
    19632012
    19642013      --conditionals->if_cmds;
     
    19742023
    19752024      if (!conditionals->if_cmds)
    1976         fatal (flocp, _("extraneous `%s'"), cmdname);
     2025        EXTRACMD ();
    19772026
    19782027      o = conditionals->if_cmds - 1;
    19792028
    19802029      if (conditionals->seen_else[o])
    1981         fatal (flocp, _("only one `else' per conditional"));
     2030        O (fatal, flocp, _("only one 'else' per conditional"));
    19822031
    19832032      /* Change the state of ignorance.  */
     
    20052054
    20062055      /* Find the length of the next word.  */
    2007       for (p = line+1; *p != '\0' && !isspace ((unsigned char)*p); ++p)
     2056      for (p = line+1; ! STOP_SET (*p, MAP_SPACE|MAP_NUL); ++p)
    20082057        ;
    20092058      len = p - line;
    20102059
    20112060      /* If it's 'else' or 'endif' or an illegal conditional, fail.  */
    2012       if (word1eq("else") || word1eq("endif")
    2013 #ifndef CONFIG_WITH_VALUE_LENGTH
    2014           || conditional_line (line, len, flocp) < 0)
    2015 #else
    2016           || conditional_line (line, eol, len, flocp) < 0)
    2017 #endif
    2018         EXTRANEOUS ();
     2061      if (word1eq ("else") || word1eq ("endif")
     2062          || conditional_line (line IF_WITH_VALUE_LENGTH_PARAM(eol), len, flocp) < 0)
     2063        EXTRATEXT ();
    20192064      else
    20202065        {
     
    20682113    }
    20692114
    2070   /* Record that we have seen an `if...' but no `else' so far.  */
     2115  /* Record that we have seen an 'if...' but no 'else' so far.  */
    20712116  conditionals->seen_else[o] = 0;
    20722117
     
    20752120    if (conditionals->ignoring[i])
    20762121      {
    2077         /* We are already ignoring, so just push a level to match the next
    2078            "else" or "endif", and keep ignoring.  We don't want to expand
    2079            variables in the condition.  */
    2080         conditionals->ignoring[o] = 1;
    2081         return 1;
     2122        /* We are already ignoring, so just push a level to match the next
     2123           "else" or "endif", and keep ignoring.  We don't want to expand
     2124           variables in the condition.  */
     2125        conditionals->ignoring[o] = 1;
     2126        return 1;
    20822127      }
    20832128
     
    20992144      p = end_of_token (var);
    21002145      i = p - var;
    2101       p = next_token (p);
     2146      NEXT_TOKEN (p);
    21022147      if (*p != '\0')
    2103         return -1;
     2148        return -1;
    21042149
    21052150      var[i] = '\0';
     
    21372182
    21382183      if (termin != ',' && termin != '"' && termin != '\'')
    2139         return -1;
     2184        return -1;
    21402185
    21412186      s1 = ++line;
    21422187      /* Find the end of the first string.  */
    21432188      if (termin == ',')
    2144         {
    2145           int count = 0;
    2146           for (; *line != '\0'; ++line)
    2147             if (*line == '(')
    2148               ++count;
    2149             else if (*line == ')')
    2150               --count;
    2151             else if (*line == ',' && count <= 0)
    2152               break;
    2153         }
     2189        {
     2190          int count = 0;
     2191          for (; *line != '\0'; ++line)
     2192            if (*line == '(')
     2193              ++count;
     2194            else if (*line == ')')
     2195              --count;
     2196            else if (*line == ',' && count <= 0)
     2197              break;
     2198        }
    21542199      else
    2155         while (*line != '\0' && *line != termin)
    2156           ++line;
     2200        while (*line != '\0' && *line != termin)
     2201          ++line;
    21572202
    21582203      if (*line == '\0')
    2159         return -1;
     2204        return -1;
    21602205
    21612206      if (termin == ',')
    2162         {
    2163           /* Strip blanks after the first string.  */
    2164           char *p = line++;
    2165           while (isblank ((unsigned char)p[-1]))
    2166             --p;
    2167           *p = '\0';
     2207        {
     2208          /* Strip blanks after the first string.  */
     2209          char *p = line++;
     2210          while (ISBLANK (p[-1]))
     2211            --p;
     2212          *p = '\0';
    21682213#ifdef CONFIG_WITH_VALUE_LENGTH
    21692214          l = p - s1;
    21702215#endif
    2171         }
     2216        }
    21722217      else
    21732218        {
     
    21752220          l = line - s1;
    21762221#endif
    2177           *line++ = '\0';
     2222          *line++ = '\0';
    21782223        }
    21792224
     
    21812226      s2 = variable_expand (s1);
    21822227      /* We must allocate a new copy of the expanded string because
    2183         variable_expand re-uses the same buffer.  */
     2228        variable_expand re-uses the same buffer.  */
    21842229      l = strlen (s2);
    21852230      s1 = alloca (l + 1);
     
    21902235
    21912236      if (termin != ',')
    2192         /* Find the start of the second string.  */
    2193         line = next_token (line);
     2237        /* Find the start of the second string.  */
     2238        NEXT_TOKEN (line);
    21942239
    21952240      termin = termin == ',' ? ')' : *line;
    21962241      if (termin != ')' && termin != '"' && termin != '\'')
    2197         return -1;
     2242        return -1;
    21982243
    21992244      /* Find the end of the second string.  */
    22002245      if (termin == ')')
    2201         {
    2202           int count = 0;
    2203           s2 = next_token (line);
    2204           for (line = s2; *line != '\0'; ++line)
    2205             {
    2206               if (*line == '(')
    2207                 ++count;
    2208               else if (*line == ')')
    2209                 {
    2210                   if (count <= 0)
    2211                     break;
    2212                   else
    2213                     --count;
    2214                 }
    2215             }
    2216         }
     2246        {
     2247          int count = 0;
     2248          s2 = next_token (line);
     2249          for (line = s2; *line != '\0'; ++line)
     2250            {
     2251              if (*line == '(')
     2252                ++count;
     2253              else if (*line == ')')
     2254                {
     2255                  if (count <= 0)
     2256                    break;
     2257                  else
     2258                    --count;
     2259                }
     2260            }
     2261        }
    22172262      else
    2218         {
    2219           ++line;
    2220           s2 = line;
    2221           while (*line != '\0' && *line != termin)
    2222             ++line;
    2223         }
     2263        {
     2264          ++line;
     2265          s2 = line;
     2266          while (*line != '\0' && *line != termin)
     2267            ++line;
     2268        }
    22242269
    22252270      if (*line == '\0')
    2226         return -1;
    2227 
    2228       *line = '\0';
     2271        return -1;
     2272
    22292273#ifdef CONFIG_WITH_VALUE_LENGTH
    22302274      l = line - s2;
    22312275#endif
    2232       line = next_token (++line);
     2276      *(line++) = '\0';
     2277      NEXT_TOKEN (line);
    22332278      if (*line != '\0')
    2234         EXTRANEOUS ();
     2279        EXTRATEXT ();
    22352280
    22362281#ifndef CONFIG_WITH_VALUE_LENGTH
     
    22912336record_target_var (struct nameseq *filenames, char *defn,
    22922337                   enum variable_origin origin, struct vmodifiers *vmod,
    2293                    const struct floc *flocp)
     2338                   const floc *flocp)
    22942339{
    22952340  struct nameseq *nextf;
     
    23052350      struct variable *v;
    23062351      const char *name = filenames->name;
    2307       const char *fname;
    23082352      const char *percent;
    23092353      struct pattern_var *p;
     2354#ifdef CONFIG_WITH_VALUE_LENGTH
     2355      const char *fname;
     2356#endif
    23102357
    23112358      nextf = filenames->next;
     
    23392386          v->value_alloc_len = v->value_length + 1;
    23402387#endif
    2341 
    2342           fname = p->target;
    23432388        }
    23442389      else
     
    23652410
    23662411          initialize_file_variables (f, 1);
    2367           fname = f->name;
    23682412
    23692413          current_variable_set_list = f->variables;
    23702414          v = try_variable_definition (flocp, defn IF_WITH_VALUE_LENGTH_PARAM(NULL), origin, 1);
    23712415          if (!v)
    2372             fatal (flocp, _("Malformed target-specific variable definition"));
     2416            O (fatal, flocp, _("Malformed target-specific variable definition"));
    23732417          current_variable_set_list = global;
    23742418        }
     
    23852429          struct variable *gv;
    23862430#ifndef CONFIG_WITH_STRCACHE2
    2387           int len = strlen(v->name);
     2431          int len = strlen (v->name);
    23882432#else
    23892433          int len = !percent
     
    23932437
    23942438          gv = lookup_variable (v->name, len);
    2395           if (gv && (gv->origin == o_env_override || gv->origin == o_command))
     2439          if (gv && v != gv
     2440              && (gv->origin == o_env_override || gv->origin == o_command))
    23962441            {
    23972442#ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE
    23982443              assert (!v->rdonly_val); /* paranoia */
    23992444#endif
    2400               if (v->value != 0)
    2401                 free (v->value);
     2445              free (v->value);
    24022446#ifndef CONFIG_WITH_VALUE_LENGTH
    24032447              v->value = xstrdup (gv->value);
     
    24202464   by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
    24212465   TWO_COLON is nonzero if a double colon was used.
    2422    If not nil, PATTERN is the `%' pattern to make this
     2466   If not nil, PATTERN is the '%' pattern to make this
    24232467   a static pattern rule, and PATTERN_PERCENT is a pointer
    2424    to the `%' within it.
     2468   to the '%' within it.
    24252469
    24262470   The links of FILENAMES are freed, and so are any names in it
     
    24322476              unsigned int cmds_started, char *commands,
    24332477              unsigned int commands_idx, int two_colon,
    2434               const struct floc *flocp)
     2478              char prefix, const floc *flocp)
    24352479{
    24362480#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
     
    24492493     See Savannah bug # 12124.  */
    24502494  if (snapped_deps)
    2451     fatal (flocp, _("prerequisites cannot be defined in recipes"));
     2495    O (fatal, flocp, _("prerequisites cannot be defined in recipes"));
    24522496
    24532497  /* Determine if this is a pattern rule or not.  */
     
    24652509      cmds->fileinfo.filenm = flocp->filenm;
    24662510      cmds->fileinfo.lineno = cmds_started;
     2511      cmds->fileinfo.offset = 0;
    24672512      cmds->commands = xstrndup (commands, commands_idx);
    24682513      cmds->command_lines = 0;
     2514      cmds->recipe_prefix = prefix;
    24692515#ifdef CONFIG_WITH_MEMORY_OPTIMIZATIONS
    24702516      cmds->refs = 0;
     
    24782524  if (depstr == 0)
    24792525    deps = 0;
    2480   else if (second_expansion && strchr (depstr, '$'))
    2481     {
    2482       deps = alloc_dep ();
    2483       deps->name = depstr;
    2484       deps->need_2nd_expansion = 1;
    2485       deps->staticpattern = pattern != 0;
    2486     }
    24872526  else
    24882527    {
    2489       deps = split_prereqs (depstr);
    2490       free (depstr);
    2491 
    2492       /* We'll enter static pattern prereqs later when we have the stem.  We
    2493          don't want to enter pattern rules at all so that we don't think that
    2494          they ought to exist (make manual "Implicit Rule Search Algorithm",
    2495          item 5c).  */
    2496       if (! pattern && ! implicit_percent)
    2497         deps = enter_prereqs (deps, NULL);
     2528      depstr = unescape_char (depstr, ':');
     2529      if (second_expansion && strchr (depstr, '$'))
     2530        {
     2531          deps = alloc_dep ();
     2532          deps->name = depstr;
     2533          deps->need_2nd_expansion = 1;
     2534          deps->staticpattern = pattern != 0;
     2535        }
     2536      else
     2537        {
     2538          deps = split_prereqs (depstr);
     2539          free (depstr);
     2540
     2541          /* We'll enter static pattern prereqs later when we have the stem.
     2542             We don't want to enter pattern rules at all so that we don't
     2543             think that they ought to exist (make manual "Implicit Rule Search
     2544             Algorithm", item 5c).  */
     2545          if (! pattern && ! implicit_percent)
     2546            deps = enter_prereqs (deps, NULL);
     2547        }
    24982548    }
    24992549
     
    25092559
    25102560      if (pattern != 0)
    2511         fatal (flocp, _("mixed implicit and static pattern rules"));
     2561        O (fatal, flocp, _("mixed implicit and static pattern rules"));
    25122562
    25132563      /* Count the targets to create an array of target names.
     
    25322582
    25332583          if (implicit_percent == 0)
    2534             fatal (flocp, _("mixed implicit and normal rules"));
    2535 
    2536           targets[c] = name;
    2537           target_pats[c] = implicit_percent;
     2584            O (fatal, flocp, _("mixed implicit and normal rules"));
     2585
     2586          targets[c] = name;
     2587          target_pats[c] = implicit_percent;
    25382588          ++c;
    25392589
     
    25652615          posix_pedantic = 1;
    25662616          define_variable_cname (".SHELLFLAGS", "-ec", o_default, 0);
     2617          /* These default values are based on IEEE Std 1003.1-2008.  */
     2618          define_variable_cname ("ARFLAGS", "-rv", o_default, 0);
     2619          define_variable_cname ("CC", "c99", o_default, 0);
     2620          define_variable_cname ("CFLAGS", "-O", o_default, 0);
     2621          define_variable_cname ("FC", "fort77", o_default, 0);
     2622          define_variable_cname ("FFLAGS", "-O 1", o_default, 0);
     2623          define_variable_cname ("SCCSGETFLAGS", "-s", o_default, 0);
    25672624        }
    25682625      else if (streq (name, ".SECONDEXPANSION"))
     
    25722629        second_target_expansion = 1;
    25732630#endif
    2574 #if !defined(WINDOWS32) && !defined (__MSDOS__) && !defined (__EMX__)
     2631#if !defined (__MSDOS__) && !defined (__EMX__)
    25752632      else if (streq (name, ".ONESHELL"))
    25762633        one_shell = 1;
     
    26212678
    26222679      /* If this is a static pattern rule:
    2623          `targets: target%pattern: prereq%pattern; recipe',
     2680         'targets: target%pattern: prereq%pattern; recipe',
    26242681         make sure the pattern matches this target name.  */
    26252682      if (pattern && !pattern_matches (pattern, pattern_percent, name))
    2626         error (flocp, _("target `%s' doesn't match the target pattern"), name);
     2683        OS (error, flocp,
     2684            _("target '%s' doesn't match the target pattern"), name);
    26272685      else if (deps)
    26282686        /* If there are multiple targets, copy the chain DEPS for all but the
     
    26332691      /* Find or create an entry in the file database for this target.  */
    26342692      if (!two_colon)
    2635         {
    2636           /* Single-colon.  Combine this rule with the file's existing record,
    2637              if any.  */
     2693        {
     2694          /* Single-colon.  Combine this rule with the file's existing record,
     2695             if any.  */
    26382696#ifndef KMK
    2639           f = enter_file (strcache_add (name));
     2697          f = enter_file (strcache_add (name));
    26402698#else  /* KMK - the name is already in the cache, don't waste time.  */
    26412699          f = enter_file (name);
    26422700#endif
    2643           if (f->double_colon)
    2644             fatal (flocp,
    2645                    _("target file `%s' has both : and :: entries"), f->name);
    2646 
    2647           /* If CMDS == F->CMDS, this target was listed in this rule
    2648              more than once.  Just give a warning since this is harmless.  */
    2649           if (cmds != 0 && cmds == f->cmds)
    2650             error (flocp,
    2651                    _("target `%s' given more than once in the same rule."),
    2652                    f->name);
    2653 
    2654           /* Check for two single-colon entries both with commands.
    2655              Check is_target so that we don't lose on files such as .c.o
    2656              whose commands were preinitialized.  */
    2657           else if (cmds != 0 && f->cmds != 0 && f->is_target)
    2658             {
    2659               error (&cmds->fileinfo,
    2660                      _("warning: overriding recipe for target `%s'"),
     2701          if (f->double_colon)
     2702            OS (fatal, flocp,
     2703                _("target file '%s' has both : and :: entries"), f->name);
     2704
     2705          /* If CMDS == F->CMDS, this target was listed in this rule
     2706             more than once.  Just give a warning since this is harmless.  */
     2707          if (cmds != 0 && cmds == f->cmds)
     2708            OS (error, flocp,
     2709                _("target '%s' given more than once in the same rule"),
     2710                f->name);
     2711
     2712          /* Check for two single-colon entries both with commands.
     2713             Check is_target so that we don't lose on files such as .c.o
     2714             whose commands were preinitialized.  */
     2715          else if (cmds != 0 && f->cmds != 0 && f->is_target)
     2716            {
     2717              size_t l = strlen (f->name);
     2718              error (&cmds->fileinfo, l,
     2719                     _("warning: overriding recipe for target '%s'"),
    26612720                     f->name);
    2662               error (&f->cmds->fileinfo,
    2663                      _("warning: ignoring old recipe for target `%s'"),
     2721              error (&f->cmds->fileinfo, l,
     2722                     _("warning: ignoring old recipe for target '%s'"),
    26642723                     f->name);
    2665             }
    2666 
    2667           /* Defining .DEFAULT with no deps or cmds clears it.  */
    2668           if (f == default_file && this == 0 && cmds == 0)
    2669             f->cmds = 0;
    2670           if (cmds != 0)
    2671             f->cmds = cmds;
     2724            }
     2725
     2726          /* Defining .DEFAULT with no deps or cmds clears it.  */
     2727          if (f == default_file && this == 0 && cmds == 0)
     2728            f->cmds = 0;
     2729          if (cmds != 0)
     2730            f->cmds = cmds;
    26722731
    26732732#ifdef CONFIG_WITH_EXPLICIT_MULTITARGET
     
    26842743
    26852744              if (f == suffix_file)
    2686                 error (flocp,
    2687                        _(".SUFFIXES encountered in an explicit multi target rule"));
     2745                O (error, flocp,
     2746                   _(".SUFFIXES encountered in an explicit multi target rule"));
    26882747            }
    26892748          prev_file = f;
    26902749#endif
    26912750
    2692           /* Defining .SUFFIXES with no dependencies clears out the list of
    2693              suffixes.  */
    2694           if (f == suffix_file && this == 0)
    2695             {
     2751          /* Defining .SUFFIXES with no dependencies clears out the list of
     2752             suffixes.  */
     2753          if (f == suffix_file && this == 0)
     2754            {
    26962755              free_dep_chain (f->deps);
    2697               f->deps = 0;
    2698             }
    2699         }
     2756              f->deps = 0;
     2757            }
     2758        }
    27002759      else
    2701         {
    2702           /* Double-colon.  Make a new record even if there already is one.  */
     2760        {
     2761          /* Double-colon.  Make a new record even if there already is one.  */
    27032762#ifndef CONFIG_WITH_STRCACHE2
    27042763          f = lookup_file (name);
     
    27072766#endif /* CONFIG_WITH_STRCACHE2 */
    27082767
    2709           /* Check for both : and :: rules.  Check is_target so we don't lose
    2710              on default suffix rules or makefiles.  */
    2711           if (f != 0 && f->is_target && !f->double_colon)
    2712             fatal (flocp,
    2713                    _("target file `%s' has both : and :: entries"), f->name);
     2768          /* Check for both : and :: rules.  Check is_target so we don't lose
     2769             on default suffix rules or makefiles.  */
     2770          if (f != 0 && f->is_target && !f->double_colon)
     2771            OS (fatal, flocp,
     2772                _("target file '%s' has both : and :: entries"), f->name);
    27142773
    27152774#ifndef KMK
    2716           f = enter_file (strcache_add (name));
     2775          f = enter_file (strcache_add (name));
    27172776#else  /* KMK - the name is already in the cache, don't waste time.  */
    2718           f = enter_file (name);
    2719 #endif
    2720           /* If there was an existing entry and it was a double-colon entry,
    2721              enter_file will have returned a new one, making it the prev
    2722              pointer of the old one, and setting its double_colon pointer to
    2723              the first one.  */
    2724           if (f->double_colon == 0)
    2725             /* This is the first entry for this name, so we must set its
    2726                double_colon pointer to itself.  */
    2727             f->double_colon = f;
    2728 
    2729           f->cmds = cmds;
    2730         }
     2777          f = enter_file (name);
     2778#endif
     2779          /* If there was an existing entry and it was a double-colon entry,
     2780             enter_file will have returned a new one, making it the prev
     2781             pointer of the old one, and setting its double_colon pointer to
     2782             the first one.  */
     2783          if (f->double_colon == 0)
     2784            /* This is the first entry for this name, so we must set its
     2785               double_colon pointer to itself.  */
     2786            f->double_colon = f;
     2787
     2788          f->cmds = cmds;
     2789        }
    27312790
    27322791      f->is_target = 1;
    27332792
    27342793      /* If this is a static pattern rule, set the stem to the part of its
    2735          name that matched the `%' in the pattern, so you can use $* in the
     2794         name that matched the '%' in the pattern, so you can use $* in the
    27362795         commands.  If we didn't do it before, enter the prereqs now.  */
    27372796      if (pattern)
     
    27962855      name = filenames->name;
    27972856      if (find_percent_cached (&name))
    2798         fatal (flocp, _("mixed implicit and normal rules"));
     2857        O (error, flocp,
     2858           _("*** mixed implicit and normal rules: deprecated syntax"));
    27992859    }
    28002860}
     
    28102870   STOPCHAR _cannot_ be '$' if IGNOREVARS is true.  */
    28112871
    2812 #ifndef CONFIG_WITH_VALUE_LENGTH
    28132872static char *
    2814 find_char_unquote (char *string, int stop1, int stop2, int blank,
    2815                    int ignorevars)
    2816 #else
    2817 static char *
    2818 find_char_unquote_2 (char *string, int stop1, int stop2, int blank,
    2819                      int ignorevars, unsigned int string_len)
    2820 #endif
     2873find_char_unquote (char *string, int map IF_WITH_VALUE_LENGTH_PARAM(unsigned int string_len))
    28212874{
    28222875#ifndef CONFIG_WITH_VALUE_LENGTH
     
    28242877#endif
    28252878  char *p = string;
    2826   register int ch; /* bird: 'optimiziations' */
    28272879#ifdef CONFIG_WITH_VALUE_LENGTH
    28282880  assert (string_len == 0 || string_len == strlen (string));
    28292881#endif
    28302882
    2831   if (ignorevars)
    2832     ignorevars = '$';
     2883  /* Always stop on NUL.  */
     2884  map |= MAP_NUL;
    28332885
    28342886  while (1)
    28352887    {
    2836       if (stop2 && blank)
    2837         while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1 && ch != stop2
    2838                && ! isblank ((unsigned char) ch))
    2839           ++p;
    2840       else if (stop2)
    2841         while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1 && ch != stop2)
    2842           ++p;
    2843       else if (blank)
    2844         while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1
    2845                && ! isblank ((unsigned char) ch))
    2846           ++p;
    2847       else
    2848         while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1)
    2849           ++p;
    2850 
    2851       if (ch == '\0')
    2852         break;
     2888      while (! STOP_SET (*p, map))
     2889        ++p;
     2890
     2891      if (*p == '\0')
     2892        break;
    28532893
    28542894      /* If we stopped due to a variable reference, skip over its contents.  */
    2855       if (ch == ignorevars)
     2895      if (STOP_SET (*p, MAP_VARIABLE))
    28562896        {
    28572897          char openparen = p[1];
     2898
     2899          /* Check if '$' is the last character in the string.  */
     2900          if (openparen == '\0')
     2901            break;
    28582902
    28592903          p += 2;
     
    28642908              unsigned int pcount = 1;
    28652909              char closeparen = (openparen == '(' ? ')' : '}');
     2910              char ch; /* bird */
    28662911
    28672912              while ((ch = *p))
     
    28842929
    28852930      if (p > string && p[-1] == '\\')
    2886         {
    2887           /* Search for more backslashes.  */
    2888           int i = -2;
    2889           while (&p[i] >= string && p[i] == '\\')
    2890             --i;
    2891           ++i;
    2892           /* Only compute the length if really needed.  */
    2893           if (string_len == 0)
    2894             string_len = strlen (string);
    2895           /* The number of backslashes is now -I.
    2896              Copy P over itself to swallow half of them.  */
    2897           memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1);
    2898           p += i/2;
    2899           if (i % 2 == 0)
    2900             /* All the backslashes quoted each other; the STOPCHAR was
    2901                unquoted.  */
    2902             return p;
    2903 
    2904           /* The STOPCHAR was quoted by a backslash.  Look for another.  */
    2905         }
     2931        {
     2932          /* Search for more backslashes.  */
     2933          int i = -2;
     2934          while (&p[i] >= string && p[i] == '\\')
     2935            --i;
     2936          ++i;
     2937          /* Only compute the length if really needed.  */
     2938          if (string_len == 0)
     2939            string_len = strlen (string);
     2940          /* The number of backslashes is now -I.
     2941             Copy P over itself to swallow half of them.  */
     2942          memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1);
     2943          p += i/2;
     2944          if (i % 2 == 0)
     2945            /* All the backslashes quoted each other; the STOPCHAR was
     2946               unquoted.  */
     2947            return p;
     2948
     2949          /* The STOPCHAR was quoted by a backslash.  Look for another.  */
     2950        }
    29062951      else
    2907         /* No backslash in sight.  */
    2908         return p;
     2952        /* No backslash in sight.  */
     2953        return p;
    29092954    }
    29102955
     
    29142959
    29152960#ifdef CONFIG_WITH_VALUE_LENGTH
    2916 /* Special case version of find_char_unquote that only takes stop1.
    2917    This is so common that it makes a lot of sense to specialize this.
    2918    */
    2919 __inline static char *
    2920 find_char_unquote_0 (char *string, int stop1, char **eosp)
     2961/* Special case version of find_char_unquote that only takes stop character.
     2962   This is so common that it makes a lot of sense to specialize this. */
     2963
     2964K_INLINE char *
     2965find_char_unquote_0 (char *string, int stop1, int map, char **eosp)
    29212966{
    29222967  unsigned int string_len = *eosp - string;
    2923   char *p = (char *)memchr (string, stop1, string_len);
     2968  char *p;
     2969
    29242970  assert (strlen (string) == string_len);
     2971  assert (!(map & MAP_VARIABLE) && map != 0);
     2972  assert ((stopchar_map[(unsigned char)stop1] & map) == map);
     2973
     2974  p = (char *)memchr (string, stop1, string_len);
    29252975  if (!p)
    29262976    return NULL;
    2927   if (p <= string || p[-1] != '\\')
     2977  if (p <= string || p[-1] != '\\') 
    29282978    return p;
    29292979
    2930   p = find_char_unquote_2 (string, stop1, 0, 0, 0, string_len);
     2980  p = find_char_unquote (string, map, string_len);
    29312981  *eosp = memchr (string, '\0', string_len);
    29322982  return p;
     
    29342984#endif
    29352985
     2986/* Unescape a character in a string.  The string is compressed onto itself.  */
     2987
     2988static char *
     2989unescape_char (char *string, int c)
     2990{
     2991  char *p = string;
     2992  char *s = string;
     2993
     2994  while (*s != '\0')
     2995    {
     2996      if (*s == '\\')
     2997        {
     2998          char *e = s;
     2999          int l;
     3000
     3001          /* We found a backslash.  See if it's escaping our character.  */
     3002          while (*e == '\\')
     3003            ++e;
     3004          l = e - s;
     3005
     3006          if (*e != c || l%2 == 0)
     3007            {
     3008              /* It's not; just take it all without unescaping.  */
     3009              memmove (p, s, l);
     3010              p += l;
     3011
     3012              // If we hit the end of the string, we're done
     3013              if (*e == '\0')
     3014                break;
     3015            }
     3016          else if (l > 1)
     3017            {
     3018              /* It is, and there's >1 backslash.  Take half of them.  */
     3019              l /= 2;
     3020              memmove (p, s, l);
     3021              p += l;
     3022            }
     3023
     3024          s = e;
     3025        }
     3026
     3027      *(p++) = *(s++);
     3028    }
     3029
     3030  *p = '\0';
     3031  return string;
     3032}
     3033
    29363034/* Search PATTERN for an unquoted % and handle quoting.  */
    29373035
     
    29393037find_percent (char *pattern)
    29403038{
    2941   return find_char_unquote (pattern, '%', 0, 0, 0);
     3039#ifndef CONFIG_WITH_VALUE_LENGTH
     3040  return find_char_unquote (pattern, MAP_PERCENT);
     3041#else
     3042  char *eos = strchr(pattern, '\0');
     3043  return find_char_unquote_0 (pattern, '%', MAP_PERCENT, &eos);
     3044#endif
    29423045}
    29433046
     
    29623065  while (1)
    29633066    {
    2964       while (*p != '\0' && *p != '%')
     3067      while (! STOP_SET (*p, MAP_PERCENT|MAP_NUL))
    29653068        ++p;
    29663069
     
    30323135 */
    30333136
    3034 static unsigned long
     3137static long
    30353138readstring (struct ebuffer *ebuf)
    30363139{
     
    31253228      len = strlen (p);
    31263229      if (len == 0)
    3127         {
    3128           /* This only happens when the first thing on the line is a '\0'.
    3129              It is a pretty hopeless case, but (wonder of wonders) Athena
    3130              lossage strikes again!  (xmkmf puts NULs in its makefiles.)
    3131              There is nothing really to be done; we synthesize a newline so
    3132              the following line doesn't appear to be part of this line.  */
    3133           error (&ebuf->floc,
    3134                  _("warning: NUL character seen; rest of line ignored"));
    3135           p[0] = '\n';
    3136           len = 1;
    3137         }
     3230        {
     3231          /* This only happens when the first thing on the line is a '\0'.
     3232             It is a pretty hopeless case, but (wonder of wonders) Athena
     3233             lossage strikes again!  (xmkmf puts NULs in its makefiles.)
     3234             There is nothing really to be done; we synthesize a newline so
     3235             the following line doesn't appear to be part of this line.  */
     3236          O (error, &ebuf->floc,
     3237             _("warning: NUL character seen; rest of line ignored"));
     3238          p[0] = '\n';
     3239          len = 1;
     3240        }
    31383241
    31393242      /* Jump past the text we just read.  */
     
    31543257        {
    31553258          --p;
    3156           p[-1] = '\n';
     3259          memmove (p-1, p, strlen (p) + 1);
    31573260        }
    31583261#endif
     
    31603263      backslash = 0;
    31613264      for (p2 = p - 2; p2 >= start; --p2)
    3162         {
    3163           if (*p2 != '\\')
    3164             break;
     3265        {
     3266          if (*p2 != '\\')
     3267            break;
    31653268          backslash = !backslash;
    3166         }
     3269        }
    31673270
    31683271      if (!backslash)
    3169         {
    3170           p[-1] = '\0';
     3272        {
     3273          p[-1] = '\0';
    31713274#ifdef CONFIG_WITH_VALUE_LENGTH
    31723275          ebuf->eol = p - 1;
    31733276#endif
    3174           break;
    3175         }
     3277          break;
     3278        }
    31763279
    31773280      /* It was a backslash/newline combo.  If we have more space, read
     
    32253328     w_dcolon       A double-colon
    32263329     w_semicolon    A semicolon
    3227      w_varassign    A variable assignment operator (=, :=, +=, >=, or ?=)
     3330     w_varassign    A variable assignment operator (=, :=, ::=, +=, >=, ?=, or !=)
    32283331
    32293332   Note that this function is only used when reading certain parts of the
     
    32393342
    32403343  /* Skip any leading whitespace.  */
    3241   while (isblank ((unsigned char)*p))
     3344  while (ISBLANK (*p))
    32423345    ++p;
    32433346
     
    32643367        case ':':
    32653368          ++p;
    3266           wtype = w_dcolon;
     3369          if (p[1] != '=')
     3370            wtype = w_dcolon;
     3371          else
     3372            {
     3373              wtype = w_varassign;
     3374              ++p;
     3375            }
    32673376          break;
    32683377
     
    32763385    case '+':
    32773386    case '?':
     3387    case '!':
    32783388#ifdef CONFIG_WITH_PREPEND_ASSIGNMENT
    32793389    case '>':
     
    32983408  /* This is some non-operator word.  A word consists of the longest
    32993409     string of characters that doesn't contain whitespace, one of [:=#],
    3300      or [?+]=, or one of the chars in the DELIM string.  */
     3410     or [?+!]=, or one of the chars in the DELIM string.  */
    33013411
    33023412  /* We start out assuming a static word; if we see a variable we'll
     
    33203430        case ':':
    33213431#ifdef HAVE_DOS_PATHS
    3322           /* A word CAN include a colon in its drive spec.  The drive
    3323              spec is allowed either at the beginning of a word, or as part
    3324              of the archive member name, like in "libfoo.a(d:/foo/bar.o)".  */
    3325           if (!(p - beg >= 2
    3326                 && (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2])
    3327                 && (p - beg == 2 || p[-3] == '(')))
    3328 #endif
    3329           goto done_word;
     3432          /* A word CAN include a colon in its drive spec.  The drive
     3433             spec is allowed either at the beginning of a word, or as part
     3434             of the archive member name, like in "libfoo.a(d:/foo/bar.o)".  */
     3435          if (!(p - beg >= 2
     3436                && (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2])
     3437                && (p - beg == 2 || p[-3] == '(')))
     3438#endif
     3439          goto done_word;
    33303440
    33313441        case '$':
     
    33333443          if (c == '$')
    33343444            break;
     3445          if (c == '\0')
     3446            goto done_word;
    33353447
    33363448          /* This is a variable reference, so note that it's expandable.
     
    34053517construct_include_path (const char **arg_dirs)
    34063518{
    3407 #ifdef VAXC             /* just don't ask ... */
     3519#ifdef VAXC             /* just don't ask ... */
    34083520  stat_t stbuf;
    34093521#else
     
    34403552    while (*arg_dirs != 0)
    34413553      {
    3442         const char *dir = *(arg_dirs++);
     3554        const char *dir = *(arg_dirs++);
    34433555        char *expanded = 0;
    34443556        int e;
    34453557
    3446         if (dir[0] == '~')
    3447           {
    3448             expanded = tilde_expand (dir);
    3449             if (expanded != 0)
    3450               dir = expanded;
    3451           }
     3558        if (dir[0] == '~')
     3559          {
     3560            expanded = tilde_expand (dir);
     3561            if (expanded != 0)
     3562              dir = expanded;
     3563          }
    34523564
    34533565        EINTRLOOP (e, stat (dir, &stbuf));
    3454         if (e == 0 && S_ISDIR (stbuf.st_mode))
     3566        if (e == 0 && S_ISDIR (stbuf.st_mode))
    34553567          {
    34563568            unsigned int len = strlen (dir);
     
    34633575          }
    34643576
    3465         if (expanded)
    3466           free (expanded);
     3577        free (expanded);
    34673578      }
    34683579
     
    34783589      {
    34793590        unsigned int len = strlen (djdir->value) + 8;
    3480         char *defdir = alloca (len + 1);
    3481 
    3482         strcat (strcpy (defdir, djdir->value), "/include");
    3483         dirs[idx++] = strcache_add (defdir);
     3591        char *defdir = alloca (len + 1);
     3592
     3593        strcat (strcpy (defdir, djdir->value), "/include");
     3594        dirs[idx++] = strcache_add (defdir);
    34843595
    34853596        if (len > max_incl_len)
     
    35363647  if (name[1] == '/' || name[1] == '\0')
    35373648    {
    3538       extern char *getenv ();
    35393649      char *home_dir;
    35403650      int is_variable;
    35413651
    35423652      {
    3543         /* Turn off --warn-undefined-variables while we expand HOME.  */
    3544         int save = warn_undefined_variables_flag;
    3545         warn_undefined_variables_flag = 0;
     3653        /* Turn off --warn-undefined-variables while we expand HOME.  */
     3654        int save = warn_undefined_variables_flag;
     3655        warn_undefined_variables_flag = 0;
    35463656
    35473657#ifndef CONFIG_WITH_VALUE_LENGTH
    3548         home_dir = allocated_variable_expand ("$(HOME)");
    3549 #else
    3550         home_dir = allocated_variable_expand_2 (STRING_SIZE_TUPLE("$(HOME)"), NULL);
    3551 #endif
    3552 
    3553         warn_undefined_variables_flag = save;
     3658        home_dir = allocated_variable_expand ("$(HOME)");
     3659#else
     3660        home_dir = allocated_variable_expand_2 (STRING_SIZE_TUPLE("$(HOME)"), NULL);
     3661#endif
     3662
     3663        warn_undefined_variables_flag = save;
    35543664      }
    35553665
    35563666      is_variable = home_dir[0] != '\0';
    35573667      if (!is_variable)
    3558         {
    3559           free (home_dir);
    3560           home_dir = getenv ("HOME");
    3561         }
     3668        {
     3669          free (home_dir);
     3670          home_dir = getenv ("HOME");
     3671        }
    35623672# if !defined(_AMIGA) && !defined(WINDOWS32)
    35633673      if (home_dir == 0 || home_dir[0] == '\0')
    3564         {
    3565           extern char *getlogin ();
    3566           char *logname = getlogin ();
    3567           home_dir = 0;
    3568           if (logname != 0)
    3569             {
    3570               struct passwd *p = getpwnam (logname);
    3571               if (p != 0)
    3572                 home_dir = p->pw_dir;
    3573             }
    3574         }
     3674        {
     3675          char *logname = getlogin ();
     3676          home_dir = 0;
     3677          if (logname != 0)
     3678            {
     3679              struct passwd *p = getpwnam (logname);
     3680              if (p != 0)
     3681                home_dir = p->pw_dir;
     3682            }
     3683        }
    35753684# endif /* !AMIGA && !WINDOWS32 */
    35763685      if (home_dir != 0)
    3577         {
    3578           char *new = xstrdup (concat (2, home_dir, name + 1));
    3579           if (is_variable)
    3580             free (home_dir);
    3581           return new;
    3582         }
     3686        {
     3687          char *new = xstrdup (concat (2, home_dir, name + 1));
     3688          if (is_variable)
     3689            free (home_dir);
     3690          return new;
     3691        }
    35833692    }
    35843693# if !defined(_AMIGA) && !defined(WINDOWS32)
     
    35883697      char *userend = strchr (name + 1, '/');
    35893698      if (userend != 0)
    3590         *userend = '\0';
     3699        *userend = '\0';
    35913700      pwent = getpwnam (name + 1);
    35923701      if (pwent != 0)
    3593         {
    3594           if (userend == 0)
    3595             return xstrdup (pwent->pw_dir);
    3596           else
    3597             return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1));
    3598         }
     3702        {
     3703          if (userend == 0)
     3704            return xstrdup (pwent->pw_dir);
     3705          else
     3706            return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1));
     3707        }
    35993708      else if (userend != 0)
    3600         *userend = '/';
     3709        *userend = '/';
    36013710    }
    36023711# endif /* !AMIGA && !WINDOWS32 */
     
    36303739
    36313740void *
    3632 parse_file_seq (char **stringp, unsigned int size, int stopchar,
     3741parse_file_seq (char **stringp, unsigned int size, int stopmap,
    36333742                const char *prefix, int flags
    36343743                IF_WITH_ALLOC_CACHES_PARAM(struct alloccache *alloc_cache) )
    36353744{
    3636   extern void dir_setup_glob (glob_t *glob);
    3637 
    36383745  /* tmp points to tmpbuf after the prefix, if any.
    36393746     tp is the end of the buffer. */
    36403747  static char *tmpbuf = NULL;
    3641   static int tmpbuf_len = 0;
    3642 
    3643   int cachep = (! (flags & PARSEFS_NOCACHE));
     3748
     3749  int cachep = NONE_SET (flags, PARSEFS_NOCACHE);
    36443750
    36453751  struct nameseq *new = 0;
     
    36653771  char *tp;
    36663772
    3667 #ifdef VMS
    3668 # define VMS_COMMA ','
    3669 #else
    3670 # define VMS_COMMA 0
    3671 #endif
     3773  /* Always stop on NUL.  */
     3774  stopmap |= MAP_NUL;
    36723775
    36733776  if (size < sizeof (struct nameseq))
    36743777    size = sizeof (struct nameseq);
    36753778
    3676   if (! (flags & PARSEFS_NOGLOB))
     3779  if (NONE_SET (flags, PARSEFS_NOGLOB))
    36773780    dir_setup_glob (&gl);
    36783781
    36793782  /* Get enough temporary space to construct the largest possible target.  */
    36803783  {
     3784    static int tmpbuf_len = 0;
    36813785    int l = strlen (*stringp) + 1;
    36823786    if (l > tmpbuf_len)
     
    36953799      const char **nlist = 0;
    36963800      char *tildep = 0;
     3801      int globme = 1;
    36973802#ifndef NO_ARCHIVES
    36983803      char *arname = 0;
     
    37043809
    37053810      /* Skip whitespace; at the end of the string or STOPCHAR we're done.  */
    3706       p = next_token (p);
    3707       if (*p == '\0' || *p == stopchar)
    3708         break;
     3811      NEXT_TOKEN (p);
     3812      if (STOP_SET (*p, stopmap))
     3813        break;
    37093814
    37103815      /* There are names left, so find the end of the next name.
    37113816         Throughout this iteration S points to the start.  */
    37123817      s = p;
    3713       p = find_char_unquote (p, stopchar, VMS_COMMA, 1, 0);
     3818      p = find_char_unquote (p, stopmap|MAP_VMSCOMMA|MAP_BLANK IF_WITH_VALUE_LENGTH_PARAM(0));
    37143819#ifdef VMS
    3715         /* convert comma separated list to space separated */
     3820        /* convert comma separated list to space separated */
    37163821      if (p && *p == ',')
    3717         *p =' ';
     3822        *p =' ';
    37183823#endif
    37193824#ifdef _AMIGA
    3720       if (stopchar == ':' && p && *p == ':'
    3721           && !(isspace ((unsigned char)p[1]) || !p[1]
    3722                || isspace ((unsigned char)p[-1])))
    3723         p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0);
     3825      if (p && STOP_SET (*p, stopmap & MAP_COLON)
     3826          && !(ISSPACE (p[1]) || !p[1] || ISSPACE (p[-1])))
     3827        p = find_char_unquote (p+1, stopmap|MAP_VMSCOMMA|MAP_BLANK);
    37243828#endif
    37253829#ifdef HAVE_DOS_PATHS
     
    37283832       Note that tokens separated by spaces should be treated as separate
    37293833       tokens since make doesn't allow path names with spaces */
    3730     if (stopchar == ':')
    3731       while (p != 0 && !isspace ((unsigned char)*p) &&
     3834    if (stopmap | MAP_COLON)
     3835      while (p != 0 && !ISSPACE (*p) &&
    37323836             (p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1]))
    3733         p = find_char_unquote (p + 1, stopchar, VMS_COMMA, 1, 0);
     3837        p = find_char_unquote (p + 1, stopmap|MAP_VMSCOMMA|MAP_BLANK IF_WITH_VALUE_LENGTH_PARAM(0));
    37343838#endif
    37353839      if (p == 0)
    3736         p = s + strlen (s);
     3840        p = s + strlen (s);
    37373841
    37383842      /* Strip leading "this directory" references.  */
    3739       if (! (flags & PARSEFS_NOSTRIP))
     3843      if (NONE_SET (flags, PARSEFS_NOSTRIP))
    37403844#ifdef VMS
    3741         /* Skip leading `[]'s.  */
    3742         while (p - s > 2 && s[0] == '[' && s[1] == ']')
    3743 #else
    3744         /* Skip leading `./'s.  */
    3745         while (p - s > 2 && s[0] == '.' && s[1] == '/')
    3746 #endif
    3747           {
     3845        /* Skip leading '[]'s. should only be one set or bug somwhere else */
     3846        if (p - s > 2 && s[0] == '[' && s[1] == ']')
     3847            s += 2;
     3848        /* Skip leading '<>'s. should only be one set or bug somwhere else */
     3849        if (p - s > 2 && s[0] == '<' && s[1] == '>')
     3850            s += 2;
     3851#endif
     3852        /* Skip leading './'s.  */
     3853        while (p - s > 2 && s[0] == '.' && s[1] == '/')
     3854          {
    37483855            /* Skip "./" and all following slashes.  */
    3749             s += 2;
    3750             while (*s == '/')
    3751               ++s;
    3752           }
     3856            s += 2;
     3857            while (*s == '/')
     3858              ++s;
     3859          }
    37533860
    37543861      /* Extract the filename just found, and skip it.
     
    37573864      if (s == p)
    37583865        {
    3759         /* The name was stripped to empty ("./"). */
    3760 #if defined(VMS)
    3761           continue;
    3762 #elif defined(_AMIGA)
     3866        /* The name was stripped to empty ("./"). */
     3867#if defined(_AMIGA)
    37633868          /* PDS-- This cannot be right!! */
    37643869          tp[0] = '\0';
     
    37723877        }
    37733878      else
    3774         {
     3879        {
    37753880#ifdef VMS
    37763881/* VMS filenames can have a ':' in them but they have to be '\'ed but we need
     
    37783883 * xstrdup called because S may be read-only string constant.
    37793884 */
    3780           char *n = tp;
    3781           while (s < p)
    3782             {
    3783               if (s[0] == '\\' && s[1] == ':')
     3885          char *n = tp;
     3886          while (s < p)
     3887            {
     3888              if (s[0] == '\\' && s[1] == ':')
    37843889                ++s;
    3785               *(n++) = *(s++);
    3786             }
     3890              *(n++) = *(s++);
     3891            }
    37873892          n[0] = '\0';
    37883893          nlen = strlen (tp);
     
    38033908
    38043909         TP == TMP means we're not already in an archive group.  Ignore
    3805          something starting with `(', as that cannot actually be an
     3910         something starting with '(', as that cannot actually be an
    38063911         archive-member reference (and treating it as such results in an empty
    38073912         file name, which causes much lossage).  Also if it ends in ")" then
     
    38113916         character, so ensure there's some word ending like that before
    38123917         considering this an archive group.  */
    3813       if (! (flags & PARSEFS_NOAR)
     3918      if (NONE_SET (flags, PARSEFS_NOAR)
    38143919          && tp == tmpbuf && tp[0] != '(' && tp[nlen-1] != ')')
    38153920        {
     
    38193924              /* This looks like the first element in an open archive group.
    38203925                 A valid group MUST have ')' as the last character.  */
    3821               const char *e = p + nlen;
     3926              const char *e = p;
    38223927              do
    38233928                {
    3824                   e = next_token (e);
     3929                  const char *o = e;
     3930                  NEXT_TOKEN (e);
    38253931                  /* Find the end of this word.  We don't want to unquote and
    38263932                     we don't care about quoting since we're looking for the
    38273933                     last char in the word. */
    3828                   while (*e != '\0' && *e != stopchar && *e != VMS_COMMA
    3829                          && ! isblank ((unsigned char) *e))
     3934                  while (! STOP_SET (*e, stopmap|MAP_BLANK|MAP_VMSCOMMA))
    38303935                    ++e;
     3936                  /* If we didn't move, we're done now.  */
     3937                  if (e == o)
     3938                    break;
    38313939                  if (e[-1] == ')')
    38323940                    {
     
    38373945                      tp = n + 1;
    38383946
    3839                       /* If we have just "lib(", part of something like
    3840                          "lib( a b)", go to the next item.  */
    3841                       if (! nlen)
    3842                         continue;
    3843 
    38443947                      /* We can stop looking now.  */
    38453948                      break;
     
    38473950                }
    38483951              while (*e != '\0');
     3952
     3953              /* If we have just "lib(", part of something like "lib( a b)",
     3954                 go to the next item.  */
     3955              if (! nlen)
     3956                continue;
    38493957            }
    38503958        }
     
    38733981      /* If we're not globbing we're done: add it to the end of the chain.
    38743982         Go to the next item in the string.  */
    3875       if (flags & PARSEFS_NOGLOB)
    3876         {
    3877           NEWELT (concat (2, prefix, tp));
     3983      if (ANY_SET (flags, PARSEFS_NOGLOB))
     3984        {
     3985          NEWELT (concat (2, prefix, tmpbuf));
    38783986          continue;
    38793987        }
     
    38823990         TP is a string in tmpbuf.  NLEN is no longer used.
    38833991         We may need to do more work: after this NAME will be set.  */
    3884       name = tp;
     3992      name = tmpbuf;
    38853993
    38863994      /* Expand tilde if applicable.  */
    3887       if (tp[0] == '~')
    3888         {
    3889           tildep = tilde_expand (tp);
    3890           if (tildep != 0)
     3995      if (tmpbuf[0] == '~')
     3996        {
     3997          tildep = tilde_expand (tmpbuf);
     3998          if (tildep != 0)
    38913999            name = tildep;
    3892         }
     4000        }
    38934001
    38944002#ifndef NO_ARCHIVES
     
    38964004         file name, and save the member name in MEMNAME.  We will glob on the
    38974005         archive name and then reattach MEMNAME later.  */
    3898       if (! (flags & PARSEFS_NOAR) && ar_name (name))
    3899         {
    3900           ar_parse_name (name, &arname, &memname);
    3901           name = arname;
    3902         }
     4006      if (NONE_SET (flags, PARSEFS_NOAR) && ar_name (name))
     4007        {
     4008          ar_parse_name (name, &arname, &memname);
     4009          name = arname;
     4010        }
    39034011#endif /* !NO_ARCHIVES */
    39044012
    3905       switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
    3906         {
    3907         case GLOB_NOSPACE:
    3908           fatal (NILF, _("virtual memory exhausted"));
    3909 
    3910         case 0:
    3911           /* Success.  */
    3912           i = gl.gl_pathc;
    3913           nlist = (const char **)gl.gl_pathv;
    3914           break;
    3915 
    3916         case GLOB_NOMATCH:
    3917           /* If we want only existing items, skip this one.  */
    3918           if (flags & PARSEFS_EXISTS)
    3919             {
    3920               i = 0;
    3921               break;
    3922             }
    3923           /* FALLTHROUGH */
    3924 
    3925         default:
    3926           /* By default keep this name.  */
     4013      /* glob() is expensive: don't call it unless we need to.  */
     4014      if (NONE_SET (flags, PARSEFS_EXISTS) && strpbrk (name, "?*[") == NULL)
     4015        {
     4016          globme = 0;
    39274017          i = 1;
    39284018          nlist = &name;
    3929           break;
    3930         }
     4019        }
     4020      else
     4021        switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
     4022          {
     4023          case GLOB_NOSPACE:
     4024            OUT_OF_MEM();
     4025
     4026          case 0:
     4027            /* Success.  */
     4028            i = gl.gl_pathc;
     4029            nlist = (const char **)gl.gl_pathv;
     4030            break;
     4031
     4032          case GLOB_NOMATCH:
     4033            /* If we want only existing items, skip this one.  */
     4034            if (ANY_SET (flags, PARSEFS_EXISTS))
     4035              {
     4036                i = 0;
     4037                break;
     4038              }
     4039            /* FALLTHROUGH */
     4040
     4041          default:
     4042            /* By default keep this name.  */
     4043            i = 1;
     4044            nlist = &name;
     4045            break;
     4046          }
    39314047
    39324048      /* For each matched element, add it to the list.  */
     
    39434059              {
    39444060                /* We got a chain of items.  Attach them.  */
    3945                 (*newp)->next = found;
     4061                if (*newp)
     4062                  (*newp)->next = found;
     4063                else
     4064                  *newp = found;
    39464065
    39474066                /* Find and set the new end.  Massage names if necessary.  */
     
    39654084          NEWELT (concat (2, prefix, nlist[i]));
    39664085
     4086      if (globme)
    39674087        globfree (&gl);
    39684088
    39694089#ifndef NO_ARCHIVES
    3970       if (arname)
    3971         free (arname);
    3972 #endif
    3973 
    3974       if (tildep)
    3975         free (tildep);
     4090      free (arname);
     4091#endif
     4092
     4093      free (tildep);
    39764094    }
    39774095
Note: See TracChangeset for help on using the changeset viewer.