Ignore:
Timestamp:
Mar 12, 2018, 8:32:29 PM (7 years ago)
Author:
bird
Message:

Imported make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6) from https://git.savannah.gnu.org/git/make.git.

File:
1 edited

Legend:

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

    r2596 r3138  
    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"
     
    3329
    3430
    35 #ifndef WINDOWS32
     31#ifdef WINDOWS32
     32#include <windows.h>
     33#include "sub_proc.h"
     34#else  /* !WINDOWS32 */
    3635#ifndef _AMIGA
    3736#ifndef VMS
     
    5453    unsigned int size;  /* Malloc'd size of buffer. */
    5554    FILE *fp;           /* File, or NULL if this is an internal buffer.  */
    56     struct floc floc;   /* Info on the file in fp (if any).  */
     55    floc floc;          /* Info on the file in fp (if any).  */
    5756  };
    5857
     
    7776
    7877
    79 /* A `struct conditionals' contains the information describing
     78/* A 'struct conditionals' contains the information describing
    8079   all the active conditionals in a makefile.
    8180
    82    The global variable `conditionals' contains the conditionals
     81   The global variable 'conditionals' contains the conditionals
    8382   information for the current makefile.  It is initialized from
    84    the static structure `toplevel_conditionals' and is later changed
     83   the static structure 'toplevel_conditionals' and is later changed
    8584   to new structures for included makefiles.  */
    8685
    8786struct conditionals
    8887  {
    89     unsigned int if_cmds;       /* Depth of conditional nesting.  */
    90     unsigned int allocated;     /* Elts allocated in following arrays.  */
    91     char *ignoring;             /* Are we ignoring or interpreting?
     88    unsigned int if_cmds;       /* Depth of conditional nesting.  */
     89    unsigned int allocated;     /* Elts allocated in following arrays.  */
     90    char *ignoring;             /* Are we ignoring or interpreting?
    9291                                   0=interpreting, 1=not yet interpreted,
    9392                                   2=already interpreted */
    94     char *seen_else;            /* Have we already seen an `else'?  */
     93    char *seen_else;            /* Have we already seen an 'else'?  */
    9594  };
    9695
     
    128127   makefile currently being read in.  */
    129128
    130 const struct floc *reading_file = 0;
    131 
    132 /* The chain of makefiles read by read_makefile.  */
    133 
    134 static struct dep *read_makefiles = 0;
    135 
    136 static int eval_makefile (const char *filename, int flags);
     129const floc *reading_file = 0;
     130
     131/* The chain of files read by read_all_makefiles.  */
     132
     133static struct goaldep *read_files = 0;
     134
     135static struct goaldep *eval_makefile (const char *filename, int flags);
    137136static void eval (struct ebuffer *buffer, int flags);
    138137
     
    142141static struct variable *do_define (char *name, enum variable_origin origin,
    143142                                   struct ebuffer *ebuf);
    144 static int conditional_line (char *line, int len, const struct floc *flocp);
     143static int conditional_line (char *line, int len, const floc *flocp);
    145144static void record_files (struct nameseq *filenames, const char *pattern,
    146145                          const char *pattern_percent, char *depstr,
    147146                          unsigned int cmds_started, char *commands,
    148147                          unsigned int commands_idx, int two_colon,
    149                           const struct floc *flocp);
     148                          char prefix, const floc *flocp);
    150149static void record_target_var (struct nameseq *filenames, char *defn,
    151150                               enum variable_origin origin,
    152151                               struct vmodifiers *vmod,
    153                                const struct floc *flocp);
     152                               const floc *flocp);
    154153static enum make_word_type get_next_mword (char *buffer, char *delim,
    155154                                           char **startp, unsigned int *length);
    156155static void remove_comments (char *line);
    157 static char *find_char_unquote (char *string, int stop1, int stop2,
    158                                 int blank, int ignorevars);
     156static char *find_char_unquote (char *string, int map);
     157static char *unescape_char (char *string, int c);
    159158
    160159
     
    162161   P must point to the word to be tested, and WLEN must be the length.
    163162*/
    164 #define word1eq(s)      (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
    165 
    166 
    167 
    168 /* Read in all the makefiles and return the chain of their names.  */
    169 
    170 struct dep *
     163#define word1eq(s)      (wlen == CSTRLEN (s) && strneq (s, p, CSTRLEN (s)))
     164
     165
     166
     167/* Read in all the makefiles and return a chain of targets to rebuild.  */
     168
     169struct goaldep *
    171170read_all_makefiles (const char **makefiles)
    172171{
     
    205204    while ((name = find_next_token ((const char **)&p, &length)) != 0)
    206205      {
    207         if (*p != '\0')
    208           *p++ = '\0';
    209         eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
     206        if (*p != '\0')
     207          *p++ = '\0';
     208        eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
    210209      }
    211210
     
    218217    while (*makefiles != 0)
    219218      {
    220         struct dep *tail = read_makefiles;
    221         register struct dep *d;
    222 
    223         if (! eval_makefile (*makefiles, 0))
    224           perror_with_name ("", *makefiles);
    225 
    226         /* Find the right element of read_makefiles.  */
    227         d = read_makefiles;
    228         while (d->next != tail)
    229           d = d->next;
    230 
    231         /* Use the storage read_makefile allocates.  */
    232         *makefiles = dep_name (d);
    233         ++num_makefiles;
    234         ++makefiles;
     219        struct goaldep *d = eval_makefile (*makefiles, 0);
     220
     221        if (errno)
     222          perror_with_name ("", *makefiles);
     223
     224        /* Reuse the storage allocated for the read_file.  */
     225        *makefiles = dep_name (d);
     226        ++num_makefiles;
     227        ++makefiles;
    235228      }
    236229
     
    239232  if (num_makefiles == 0)
    240233    {
    241       static char *default_makefiles[] =
     234      static const char *default_makefiles[] =
    242235#ifdef VMS
    243         /* all lower case since readdir() (the vms version) 'lowercasifies' */
    244         { "makefile.vms", "gnumakefile.", "makefile.", 0 };
     236        /* all lower case since readdir() (the vms version) 'lowercasifies' */
     237        /* TODO: Above is not always true, this needs more work */
     238        { "makefile.vms", "gnumakefile", "makefile", 0 };
    245239#else
    246240#ifdef _AMIGA
    247         { "GNUmakefile", "Makefile", "SMakefile", 0 };
     241        { "GNUmakefile", "Makefile", "SMakefile", 0 };
    248242#else /* !Amiga && !VMS */
    249         { "GNUmakefile", "makefile", "Makefile", 0 };
     243#ifdef WINDOWS32
     244        { "GNUmakefile", "makefile", "Makefile", "makefile.mak", 0 };
     245#else /* !Amiga && !VMS && !WINDOWS32 */
     246        { "GNUmakefile", "makefile", "Makefile", 0 };
     247#endif /* !Amiga && !VMS && !WINDOWS32 */
    250248#endif /* AMIGA */
    251249#endif /* VMS */
    252       register char **p = default_makefiles;
     250      const char **p = default_makefiles;
    253251      while (*p != 0 && !file_exists_p (*p))
    254         ++p;
     252        ++p;
    255253
    256254      if (*p != 0)
    257         {
    258           if (! eval_makefile (*p, 0))
    259             perror_with_name ("", *p);
    260         }
     255        {
     256          eval_makefile (*p, 0);
     257          if (errno)
     258            perror_with_name ("", *p);
     259        }
    261260      else
    262         {
    263           /* No default makefile was found.  Add the default makefiles to the
    264              `read_makefiles' chain so they will be updated if possible.  */
    265           struct dep *tail = read_makefiles;
    266           /* Add them to the tail, after any MAKEFILES variable makefiles.  */
    267           while (tail != 0 && tail->next != 0)
    268             tail = tail->next;
    269           for (p = default_makefiles; *p != 0; ++p)
    270             {
    271               struct dep *d = alloc_dep ();
    272               d->file = enter_file (strcache_add (*p));
    273               d->dontcare = 1;
    274               /* Tell update_goal_chain to bail out as soon as this file is
    275                  made, and main not to die if we can't make this file.  */
    276               d->changed = RM_DONTCARE;
    277               if (tail == 0)
    278                 read_makefiles = d;
    279               else
    280                 tail->next = d;
    281               tail = d;
    282             }
    283           if (tail != 0)
    284             tail->next = 0;
    285         }
    286     }
    287 
    288   return read_makefiles;
     261        {
     262          /* No default makefile was found.  Add the default makefiles to the
     263             'read_files' chain so they will be updated if possible.  */
     264          struct goaldep *tail = read_files;
     265          /* Add them to the tail, after any MAKEFILES variable makefiles.  */
     266          while (tail != 0 && tail->next != 0)
     267            tail = tail->next;
     268          for (p = default_makefiles; *p != 0; ++p)
     269            {
     270              struct goaldep *d = alloc_goaldep ();
     271              d->file = enter_file (strcache_add (*p));
     272              /* Tell update_goal_chain to bail out as soon as this file is
     273                 made, and main not to die if we can't make this file.  */
     274              d->flags = RM_DONTCARE;
     275              if (tail == 0)
     276                read_files = d;
     277              else
     278                tail->next = d;
     279              tail = d;
     280            }
     281          if (tail != 0)
     282            tail->next = 0;
     283        }
     284    }
     285
     286  return read_files;
    289287}
    290288
     
    309307{
    310308  /* Free any space allocated by conditional_line.  */
    311   if (conditionals->ignoring)
    312     free (conditionals->ignoring);
    313   if (conditionals->seen_else)
    314     free (conditionals->seen_else);
     309  free (conditionals->ignoring);
     310  free (conditionals->seen_else);
    315311
    316312  /* Restore state.  */
     
    319315
    320316
    321 static int
     317static struct goaldep *
    322318eval_makefile (const char *filename, int flags)
    323319{
    324   struct dep *deps;
     320  struct goaldep *deps;
    325321  struct ebuffer ebuf;
    326   const struct floc *curfile;
     322  const floc *curfile;
    327323  char *expanded = 0;
    328324  int makefile_errno;
    329325
    330   filename = strcache_add (filename);
    331   ebuf.floc.filenm = filename;
     326  ebuf.floc.filenm = filename; /* Use the original file name.  */
    332327  ebuf.floc.lineno = 1;
     328  ebuf.floc.offset = 0;
    333329
    334330  if (ISDB (DB_VERBOSE))
    335331    {
    336       printf (_("Reading makefile `%s'"), filename);
     332      printf (_("Reading makefile '%s'"), filename);
    337333      if (flags & RM_NO_DEFAULT_GOAL)
    338         printf (_(" (no default goal)"));
     334        printf (_(" (no default goal)"));
    339335      if (flags & RM_INCLUDED)
    340         printf (_(" (search path)"));
     336        printf (_(" (search path)"));
    341337      if (flags & RM_DONTCARE)
    342         printf (_(" (don't care)"));
     338        printf (_(" (don't care)"));
    343339      if (flags & RM_NO_TILDE)
    344         printf (_(" (no ~ expansion)"));
     340        printf (_(" (no ~ expansion)"));
    345341      puts ("...");
    346342    }
     
    348344  /* First, get a stream to read.  */
    349345
    350   /* Expand ~ in FILENAME unless it came from `include',
     346  /* Expand ~ in FILENAME unless it came from 'include',
    351347     in which case it was already done.  */
    352348  if (!(flags & RM_NO_TILDE) && filename[0] == '~')
     
    354350      expanded = tilde_expand (filename);
    355351      if (expanded != 0)
    356         filename = expanded;
    357     }
    358 
    359   ebuf.fp = fopen (filename, "r");
     352        filename = expanded;
     353    }
     354
     355  ENULLLOOP (ebuf.fp, fopen (filename, "r"));
     356
    360357  /* Save the error code so we print the right message later.  */
    361358  makefile_errno = errno;
    362359
     360  /* Check for unrecoverable errors: out of mem or FILE slots.  */
     361  switch (makefile_errno)
     362    {
     363#ifdef EMFILE
     364    case EMFILE:
     365#endif
     366#ifdef ENFILE
     367    case ENFILE:
     368#endif
     369    case ENOMEM:
     370      {
     371        const char *err = strerror (makefile_errno);
     372        OS (fatal, reading_file, "%s", err);
     373      }
     374    }
     375
    363376  /* If the makefile wasn't found and it's either a makefile from
    364      the `MAKEFILES' variable or an included makefile,
     377     the 'MAKEFILES' variable or an included makefile,
    365378     search the included makefile search path for this makefile.  */
    366379  if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/')
     
    368381      unsigned int i;
    369382      for (i = 0; include_directories[i] != 0; ++i)
    370         {
    371           const char *included = concat (3, include_directories[i],
     383        {
     384          const char *included = concat (3, include_directories[i],
    372385                                         "/", filename);
    373           ebuf.fp = fopen (included, "r");
    374           if (ebuf.fp)
    375             {
    376               filename = strcache_add (included);
    377               break;
    378             }
    379         }
    380     }
     386          ebuf.fp = fopen (included, "r");
     387          if (ebuf.fp)
     388            {
     389              filename = included;
     390              break;
     391            }
     392        }
     393    }
     394
     395  /* Now we have the final name for this makefile. Enter it into
     396     the cache.  */
     397  filename = strcache_add (filename);
    381398
    382399  /* Add FILENAME to the chain of read makefiles.  */
    383   deps = alloc_dep ();
    384   deps->next = read_makefiles;
    385   read_makefiles = deps;
     400  deps = alloc_goaldep ();
     401  deps->next = read_files;
     402  read_files = deps;
    386403  deps->file = lookup_file (filename);
    387404  if (deps->file == 0)
    388405    deps->file = enter_file (filename);
    389406  filename = deps->file->name;
    390   deps->changed = flags;
    391   if (flags & RM_DONTCARE)
    392     deps->dontcare = 1;
    393 
    394   if (expanded)
    395     free (expanded);
     407  deps->flags = flags;
     408
     409  free (expanded);
    396410
    397411  /* If the makefile can't be found at all, give up entirely.  */
     
    400414    {
    401415      /* If we did some searching, errno has the error from the last
    402          attempt, rather from FILENAME itself.  Restore it in case the
    403         caller wants to use it in a message.  */
     416         attempt, rather from FILENAME itself.  Store it in case the
     417        caller wants to use it in a message.  */
    404418      errno = makefile_errno;
    405       return 0;
     419      return deps;
    406420    }
    407421
     
    433447  alloca (0);
    434448
    435   return 1;
     449  errno = 0;
     450  return deps;
    436451}
    437452
    438453void
    439 eval_buffer (char *buffer)
     454eval_buffer (char *buffer, const floc *flocp)
    440455{
    441456  struct ebuffer ebuf;
    442457  struct conditionals *saved;
    443458  struct conditionals new;
    444   const struct floc *curfile;
     459  const floc *curfile;
    445460
    446461  /* Evaluate the buffer */
     
    450465  ebuf.fp = NULL;
    451466
    452   if (reading_file)
     467  if (flocp)
     468    ebuf.floc = *flocp;
     469  else if (reading_file)
    453470    ebuf.floc = *reading_file;
    454471  else
    455     ebuf.floc.filenm = NULL;
     472    {
     473      ebuf.floc.filenm = NULL;
     474      ebuf.floc.lineno = 1;
     475      ebuf.floc.offset = 0;
     476    }
    456477
    457478  curfile = reading_file;
     
    488509
    489510  /* Find the start of the next token.  If there isn't one we're done.  */
    490   line = next_token (line);
     511  NEXT_TOKEN (line);
    491512  if (*line == '\0')
    492513    return (char *)line;
     
    497518      int wlen;
    498519      const char *p2;
    499       enum variable_flavor flavor;
    500 
    501       p2 = parse_variable_definition (p, &flavor);
     520      struct variable v;
     521
     522      p2 = parse_variable_definition (p, &v);
    502523
    503524      /* If this is a variable assignment, we're done.  */
     
    560581  unsigned int cmds_started, tgts_started;
    561582  int ignoring = 0, in_ignored_define = 0;
    562   int no_targets = 0;           /* Set when reading a rule without targets.  */
     583  int no_targets = 0;           /* Set when reading a rule without targets.  */
    563584  struct nameseq *filenames = 0;
    564585  char *depstr = 0;
    565586  long nlines = 0;
    566587  int two_colon = 0;
     588  char prefix = cmd_prefix;
    567589  const char *pattern = 0;
    568590  const char *pattern_percent;
    569   struct floc *fstart;
    570   struct floc fi;
    571 
    572 #define record_waiting_files()                                                \
    573   do                                                                          \
    574     {                                                                         \
    575       if (filenames != 0)                                                     \
     591  floc *fstart;
     592  floc fi;
     593
     594#define record_waiting_files()                                                \
     595  do                                                                          \
     596    {                                                                         \
     597      if (filenames != 0)                                                     \
    576598        {                                                                     \
    577           fi.lineno = tgts_started;                                           \
    578           record_files (filenames, pattern, pattern_percent, depstr,          \
     599          fi.lineno = tgts_started;                                           \
     600          fi.offset = 0;                                                      \
     601          record_files (filenames, pattern, pattern_percent, depstr,          \
    579602                        cmds_started, commands, commands_idx, two_colon,      \
    580                         &fi);                                                 \
    581           filenames = 0;                                                      \
     603                        prefix, &fi);                                         \
     604          filenames = 0;                                                      \
    582605        }                                                                     \
    583       commands_idx = 0;                                                       \
     606      commands_idx = 0;                                                       \
    584607      no_targets = 0;                                                         \
    585608      pattern = 0;                                                            \
     
    598621
    599622     When you see a "continue" in the loop below, that means we are moving on
    600      to the next line _without_ ending any rule that we happen to be working
    601      with at the moment.  If you see a "goto rule_complete", then the
    602      statement we just parsed also finishes the previous rule.  */
     623     to the next line.  If you see record_waiting_files(), then the statement
     624     we are parsing also finishes the previous rule.  */
    603625
    604626  commands = xmalloc (200);
     
    622644        break;
    623645
     646      line = ebuf->buffer;
     647
     648      /* If this is the first line, check for a UTF-8 BOM and skip it.  */
     649      if (ebuf->floc.lineno == 1 && line[0] == (char)0xEF
     650          && line[1] == (char)0xBB && line[2] == (char)0xBF)
     651        {
     652          line += 3;
     653          if (ISDB(DB_BASIC))
     654            {
     655              if (ebuf->floc.filenm)
     656                printf (_("Skipping UTF-8 BOM in makefile '%s'\n"),
     657                        ebuf->floc.filenm);
     658              else
     659                printf (_("Skipping UTF-8 BOM in makefile buffer\n"));
     660            }
     661        }
     662
    624663      /* If this line is empty, skip it.  */
    625       line = ebuf->buffer;
    626664      if (line[0] == '\0')
    627665        continue;
     
    630668
    631669      /* Check for a shell command line first.
    632          If it is not one, we can stop treating tab specially.  */
     670         If it is not one, we can stop treating cmd_prefix specially.  */
    633671      if (line[0] == cmd_prefix)
    634         {
    635           if (no_targets)
    636             /* Ignore the commands in a rule with no targets.  */
    637             continue;
    638 
    639           /* If there is no preceding rule line, don't treat this line
    640              as a command, even though it begins with a recipe prefix.
    641              SunOS 4 make appears to behave this way.  */
    642 
    643           if (filenames != 0)
    644             {
    645               if (ignoring)
    646                 /* Yep, this is a shell command, and we don't care.  */
    647                 continue;
    648 
    649               /* Append this command line to the line being accumulated.
    650                  Strip command prefix chars that appear after newlines.  */
    651               if (commands_idx == 0)
    652                 cmds_started = ebuf->floc.lineno;
    653 
    654               if (linelen + commands_idx > commands_len)
    655                 {
    656                   commands_len = (linelen + commands_idx) * 2;
    657                   commands = xrealloc (commands, commands_len);
    658                 }
    659               p = &commands[commands_idx];
    660               p2 = line + 1;
    661               while (--linelen)
     672        {
     673          if (no_targets)
     674            /* Ignore the commands in a rule with no targets.  */
     675            continue;
     676
     677          /* If there is no preceding rule line, don't treat this line
     678             as a command, even though it begins with a recipe prefix.
     679             SunOS 4 make appears to behave this way.  */
     680
     681          if (filenames != 0)
     682            {
     683              if (ignoring)
     684                /* Yep, this is a shell command, and we don't care.  */
     685                continue;
     686
     687              if (commands_idx == 0)
     688                cmds_started = ebuf->floc.lineno;
     689
     690              /* Append this command line to the line being accumulated.
     691                 Skip the initial command prefix character.  */
     692              if (linelen + commands_idx > commands_len)
    662693                {
    663                   ++commands_idx;
    664                   *(p++) = *p2;
    665                   if (p2[0] == '\n' && p2[1] == cmd_prefix)
    666                     {
    667                       ++p2;
    668                       --linelen;
    669                     }
    670                   ++p2;
     694                  commands_len = (linelen + commands_idx) * 2;
     695                  commands = xrealloc (commands, commands_len);
    671696                }
    672               *p = '\n';
    673               ++commands_idx;
    674 
    675               continue;
    676             }
    677         }
     697              memcpy (&commands[commands_idx], line + 1, linelen - 1);
     698              commands_idx += linelen - 1;
     699              commands[commands_idx++] = '\n';
     700              continue;
     701            }
     702        }
    678703
    679704      /* This line is not a shell command line.  Don't worry about whitespace.
     
    682707
    683708      if (collapsed_length < linelen+1)
    684         {
    685           collapsed_length = linelen+1;
    686           if (collapsed)
    687             free (collapsed);
     709        {
     710          collapsed_length = linelen+1;
     711          free (collapsed);
    688712          /* Don't need xrealloc: we don't need to preserve the content.  */
    689           collapsed = xmalloc (collapsed_length);
    690         }
     713          collapsed = xmalloc (collapsed_length);
     714        }
    691715      strcpy (collapsed, line);
    692716      /* Collapse continuation lines.  */
     
    696720      /* Get rid if starting space (including formfeed, vtab, etc.)  */
    697721      p = collapsed;
    698       while (isspace ((unsigned char)*p))
    699         ++p;
     722      NEXT_TOKEN (p);
    700723
    701724      /* See if this is a variable assignment.  We need to do this early, to
    702725         allow variables with names like 'ifdef', 'export', 'private', etc.  */
    703       p = parse_var_assignment(p, &vmod);
     726      p = parse_var_assignment (p, &vmod);
    704727      if (vmod.assign_v)
    705728        {
     
    708731
    709732          /* If we're ignoring then we're done now.  */
    710           if (ignoring)
     733          if (ignoring)
    711734            {
    712735              if (vmod.define_v)
     
    715738            }
    716739
     740          /* Variable assignment ends the previous rule.  */
     741          record_waiting_files ();
     742
    717743          if (vmod.undefine_v)
    718744          {
    719745            do_undefine (p, origin, ebuf);
    720 
    721             /* This line has been dealt with.  */
    722             goto rule_complete;
     746            continue;
    723747          }
    724748          else if (vmod.define_v)
     
    735759
    736760          /* This line has been dealt with.  */
    737           goto rule_complete;
     761          continue;
    738762        }
    739763
    740764      /* If this line is completely empty, ignore it.  */
    741765      if (*p == '\0')
    742         continue;
     766        continue;
    743767
    744768      p2 = end_of_token (p);
    745769      wlen = p2 - p;
    746       p2 = next_token (p2);
     770      NEXT_TOKEN (p2);
    747771
    748772      /* If we're in an ignored define, skip this line (but maybe get out).  */
    749773      if (in_ignored_define)
    750         {
     774        {
    751775          /* See if this is an endef line (plus optional comment).  */
    752           if (word1eq ("endef") && (*p2 == '\0' || *p2 == '#'))
     776          if (word1eq ("endef") && STOP_SET (*p2, MAP_COMMENT|MAP_NUL))
    753777            in_ignored_define = 0;
    754778
    755           continue;
    756         }
     779          continue;
     780        }
    757781
    758782      /* Check for conditional state changes.  */
     
    762786          {
    763787            if (i == -1)
    764               fatal (fstart, _("invalid syntax in conditional"));
     788              O (fatal, fstart, _("invalid syntax in conditional"));
    765789
    766790            ignoring = i;
     
    771795      /* Nothing to see here... move along.  */
    772796      if (ignoring)
    773         continue;
     797        continue;
    774798
    775799      /* Manage the "export" keyword used outside of variable assignment
    776800         as well as "unexport".  */
    777801      if (word1eq ("export") || word1eq ("unexport"))
    778         {
     802        {
    779803          int exporting = *p == 'u' ? 0 : 1;
    780804
     805          /* Export/unexport ends the previous rule.  */
     806          record_waiting_files ();
     807
    781808          /* (un)export by itself causes everything to be (un)exported. */
    782           if (*p2 == '\0')
     809          if (*p2 == '\0')
    783810            export_all_variables = exporting;
    784811          else
     
    797824                  struct variable *v = lookup_variable (p, l);
    798825                  if (v == 0)
    799                     v = define_variable_loc (p, l, "", o_file, 0, fstart);
     826                    v = define_variable_global (p, l, "", o_file, 0, fstart);
    800827                  v->export = exporting ? v_export : v_noexport;
    801828                }
     
    803830              free (ap);
    804831            }
    805           goto rule_complete;
    806         }
     832          continue;
     833        }
    807834
    808835      /* Handle the special syntax for vpath.  */
    809836      if (word1eq ("vpath"))
    810         {
     837        {
    811838          const char *cp;
    812           char *vpat;
    813           unsigned int l;
    814           cp = variable_expand (p2);
    815           p = find_next_token (&cp, &l);
    816           if (p != 0)
    817             {
    818               vpat = xstrndup (p, l);
    819               p = find_next_token (&cp, &l);
    820               /* No searchpath means remove all previous
    821                  selective VPATH's with the same pattern.  */
    822             }
    823           else
    824             /* No pattern means remove all previous selective VPATH's.  */
    825             vpat = 0;
    826           construct_vpath_list (vpat, p);
    827           if (vpat != 0)
    828             free (vpat);
    829 
    830           goto rule_complete;
    831         }
     839          char *vpat;
     840          unsigned int l;
     841
     842          /* vpath ends the previous rule.  */
     843          record_waiting_files ();
     844
     845          cp = variable_expand (p2);
     846          p = find_next_token (&cp, &l);
     847          if (p != 0)
     848            {
     849              vpat = xstrndup (p, l);
     850              p = find_next_token (&cp, &l);
     851              /* No searchpath means remove all previous
     852                 selective VPATH's with the same pattern.  */
     853            }
     854          else
     855            /* No pattern means remove all previous selective VPATH's.  */
     856            vpat = 0;
     857          construct_vpath_list (vpat, p);
     858          free (vpat);
     859
     860          continue;
     861        }
    832862
    833863      /* Handle include and variants.  */
    834864      if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude"))
    835         {
    836           /* We have found an `include' line specifying a nested
    837              makefile to be read at this point.  */
    838           struct conditionals *save;
     865        {
     866          /* We have found an 'include' line specifying a nested
     867             makefile to be read at this point.  */
     868          struct conditionals *save;
    839869          struct conditionals new_conditionals;
    840           struct nameseq *files;
    841           /* "-include" (vs "include") says no error if the file does not
    842              exist.  "sinclude" is an alias for this from SGI.  */
    843           int noerror = (p[0] != 'i');
    844 
    845           p = allocated_variable_expand (p2);
     870          struct nameseq *files;
     871          /* "-include" (vs "include") says no error if the file does not
     872             exist.  "sinclude" is an alias for this from SGI.  */
     873          int noerror = (p[0] != 'i');
     874
     875          /* Include ends the previous rule.  */
     876          record_waiting_files ();
     877
     878          p = allocated_variable_expand (p2);
    846879
    847880          /* If no filenames, it's a no-op.  */
    848           if (*p == '\0')
     881          if (*p == '\0')
    849882            {
    850883              free (p);
     
    852885            }
    853886
    854           /* Parse the list of file names.  Don't expand archive references!  */
    855           p2 = p;
    856           files = PARSE_FILE_SEQ (&p2, struct nameseq, '\0', NULL,
     887          /* Parse the list of file names.  Don't expand archive references!  */
     888          p2 = p;
     889          files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL,
    857890                                  PARSEFS_NOAR);
    858           free (p);
    859 
    860           /* Save the state of conditionals and start
    861              the included makefile with a clean slate.  */
    862           save = install_conditionals (&new_conditionals);
    863 
    864           /* Record the rules that are waiting so they will determine
    865              the default goal before those in the included makefile.  */
    866           record_waiting_files ();
    867 
    868           /* Read each included makefile.  */
    869           while (files != 0)
    870             {
    871               struct nameseq *next = files->next;
    872               const char *name = files->name;
     891          free (p);
     892
     893          /* Save the state of conditionals and start
     894             the included makefile with a clean slate.  */
     895          save = install_conditionals (&new_conditionals);
     896
     897          /* Record the rules that are waiting so they will determine
     898             the default goal before those in the included makefile.  */
     899          record_waiting_files ();
     900
     901          /* Read each included makefile.  */
     902          while (files != 0)
     903            {
     904              struct nameseq *next = files->next;
     905              int flags = (RM_INCLUDED | RM_NO_TILDE
     906                           | (noerror ? RM_DONTCARE : 0)
     907                           | (set_default ? 0 : RM_NO_DEFAULT_GOAL));
     908
     909              struct goaldep *d = eval_makefile (files->name, flags);
     910
     911              if (errno)
     912                {
     913                  d->error = (unsigned short)errno;
     914                  d->floc = *fstart;
     915                }
     916
     917              free_ns (files);
     918              files = next;
     919            }
     920
     921          /* Restore conditional state.  */
     922          restore_conditionals (save);
     923
     924          continue;
     925        }
     926
     927      /* Handle the load operations.  */
     928      if (word1eq ("load") || word1eq ("-load"))
     929        {
     930          /* A 'load' line specifies a dynamic object to load.  */
     931          struct nameseq *files;
     932          int noerror = (p[0] == '-');
     933
     934          /* Load ends the previous rule.  */
     935          record_waiting_files ();
     936
     937          p = allocated_variable_expand (p2);
     938
     939          /* If no filenames, it's a no-op.  */
     940          if (*p == '\0')
     941            {
     942              free (p);
     943              continue;
     944            }
     945
     946          /* Parse the list of file names.
     947             Don't expand archive references or strip "./"  */
     948          p2 = p;
     949          files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL,
     950                                  PARSEFS_NOAR);
     951          free (p);
     952
     953          /* Load each file.  */
     954          while (files != 0)
     955            {
     956              struct nameseq *next = files->next;
     957              const char *name = files->name;
     958              struct goaldep *deps;
    873959              int r;
    874960
    875               free_ns (files);
    876               files = next;
    877 
    878               r = eval_makefile (name,
    879                                  (RM_INCLUDED | RM_NO_TILDE
    880                                   | (noerror ? RM_DONTCARE : 0)
    881                                   | (set_default ? 0 : RM_NO_DEFAULT_GOAL)));
    882               if (!r && !noerror)
    883                 error (fstart, "%s: %s", name, strerror (errno));
    884             }
    885 
    886           /* Restore conditional state.  */
    887           restore_conditionals (save);
    888 
    889           goto rule_complete;
    890         }
     961              /* Load the file.  0 means failure.  */
     962              r = load_file (&ebuf->floc, &name, noerror);
     963              if (! r && ! noerror)
     964                OS (fatal, &ebuf->floc, _("%s: failed to load"), name);
     965
     966              free_ns (files);
     967              files = next;
     968
     969              /* Return of -1 means a special load: don't rebuild it.  */
     970              if (r == -1)
     971                continue;
     972
     973              /* It succeeded, so add it to the list "to be rebuilt".  */
     974              deps = alloc_goaldep ();
     975              deps->next = read_files;
     976              read_files = deps;
     977              deps->file = lookup_file (name);
     978              if (deps->file == 0)
     979                deps->file = enter_file (name);
     980              deps->file->loaded = 1;
     981            }
     982
     983          continue;
     984        }
    891985
    892986      /* This line starts with a tab but was not caught above because there
     
    894988         variable definition.  But now we know it is definitely lossage.  */
    895989      if (line[0] == cmd_prefix)
    896         fatal(fstart, _("recipe commences before first target"));
     990        O (fatal, fstart, _("recipe commences before first target"));
    897991
    898992      /* This line describes some target files.  This is complicated by
    899993         the existence of target-specific variables, because we can't
    900994         expand the entire line until we know if we have one or not.  So
    901          we expand the line word by word until we find the first `:',
     995         we expand the line word by word until we find the first ':',
    902996         then check to see if it's a target-specific variable.
    903997
    904          In this algorithm, `lb_next' will point to the beginning of the
    905          unexpanded parts of the input buffer, while `p2' points to the
     998         In this algorithm, 'lb_next' will point to the beginning of the
     999         unexpanded parts of the input buffer, while 'p2' points to the
    9061000         parts of the expanded buffer we haven't searched yet. */
    9071001
     
    9201014        /* Search the line for an unquoted ; that is not after an
    9211015           unquoted #.  */
    922         cmdleft = find_char_unquote (line, ';', '#', 0, 1);
     1016        cmdleft = find_char_unquote (line, MAP_SEMI|MAP_COMMENT|MAP_VARIABLE);
    9231017        if (cmdleft != 0 && *cmdleft == '#')
    9241018          {
     
    9381032           beginning, expanding as we go, and looking for "interesting"
    9391033           chars.  The first word is always expandable.  */
    940         wtype = get_next_mword(line, NULL, &lb_next, &wlen);
     1034        wtype = get_next_mword (line, NULL, &lb_next, &wlen);
    9411035        switch (wtype)
    9421036          {
    9431037          case w_eol:
    9441038            if (cmdleft != 0)
    945               fatal(fstart, _("missing rule before recipe"));
     1039              O (fatal, fstart, _("missing rule before recipe"));
    9461040            /* This line contained something but turned out to be nothing
    9471041               but whitespace (a comment?).  */
     
    9591053          }
    9601054
    961         p2 = variable_expand_string(NULL, lb_next, wlen);
     1055        p2 = variable_expand_string (NULL, lb_next, wlen);
    9621056
    9631057        while (1)
     
    9671061              {
    9681062                /* Look for a semicolon in the expanded line.  */
    969                 cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
     1063                cmdleft = find_char_unquote (p2, MAP_SEMI);
    9701064
    9711065                if (cmdleft != 0)
     
    9731067                    unsigned long p2_off = p2 - variable_buffer;
    9741068                    unsigned long cmd_off = cmdleft - variable_buffer;
    975                     char *pend = p2 + strlen(p2);
     1069                    char *pend = p2 + strlen (p2);
    9761070
    9771071                    /* Append any remnants of lb, then cut the line short
     
    9831077                       and into a command script.  However, the old parser
    9841078                       expanded the whole line, so we continue that for
    985                        backwards-compatiblity.  Also, it wouldn't be
     1079                       backwards-compatibility.  Also, it wouldn't be
    9861080                       entirely consistent, since we do an unconditional
    9871081                       expand below once we know we don't have a
    9881082                       target-specific variable. */
    989                     (void)variable_expand_string(pend, lb_next, (long)-1);
    990                     lb_next += strlen(lb_next);
     1083                    (void)variable_expand_string (pend, lb_next, (long)-1);
     1084                    lb_next += strlen (lb_next);
    9911085                    p2 = variable_buffer + p2_off;
    9921086                    cmdleft = variable_buffer + cmd_off + 1;
     
    9941088              }
    9951089
    996             colonp = find_char_unquote(p2, ':', 0, 0, 0);
     1090            colonp = find_char_unquote (p2, MAP_COLON);
    9971091#ifdef HAVE_DOS_PATHS
    9981092            /* The drive spec brain-damage strikes again...  */
     
    10031097                   colonp > p2 && isalpha ((unsigned char)colonp[-1]) &&
    10041098                   (colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0))
    1005               colonp = find_char_unquote(colonp + 1, ':', 0, 0, 0);
     1099              colonp = find_char_unquote (colonp + 1, MAP_COLON);
    10061100#endif
    10071101            if (colonp != 0)
    10081102              break;
    10091103
    1010             wtype = get_next_mword(lb_next, NULL, &lb_next, &wlen);
     1104            wtype = get_next_mword (lb_next, NULL, &lb_next, &wlen);
    10111105            if (wtype == w_eol)
    10121106              break;
    10131107
    1014             p2 += strlen(p2);
     1108            p2 += strlen (p2);
    10151109            *(p2++) = ' ';
    1016             p2 = variable_expand_string(p2, lb_next, wlen);
     1110            p2 = variable_expand_string (p2, lb_next, wlen);
    10171111            /* We don't need to worry about cmdleft here, because if it was
    10181112               found in the variable_buffer the entire buffer has already
     
    10271121        if (wtype == w_eol)
    10281122          {
    1029             if (*p2 != '\0')
    1030               /* There's no need to be ivory-tower about this: check for
    1031                  one of the most common bugs found in makefiles...  */
    1032               fatal (fstart, _("missing separator%s"),
    1033                      (cmd_prefix == '\t' && !strneq(line, "        ", 8))
    1034                      ? "" : _(" (did you mean TAB instead of 8 spaces?)"));
    1035             continue;
     1123            if (*p2 == '\0')
     1124              continue;
     1125
     1126            /* There's no need to be ivory-tower about this: check for
     1127               one of the most common bugs found in makefiles...  */
     1128            if (cmd_prefix == '\t' && strneq (line, "        ", 8))
     1129              O (fatal, fstart, _("missing separator (did you mean TAB instead of 8 spaces?)"));
     1130            else
     1131              O (fatal, fstart, _("missing separator"));
    10361132          }
    10371133
    10381134        /* Make the colon the end-of-string so we know where to stop
    1039            looking for targets.  */
     1135           looking for targets.  Start there again once we're done.  */
    10401136        *colonp = '\0';
    1041         filenames = PARSE_FILE_SEQ (&p2, struct nameseq, '\0', NULL, 0);
    1042         *p2 = ':';
     1137        filenames = PARSE_SIMPLE_SEQ (&p2, struct nameseq);
     1138        *colonp = ':';
     1139        p2 = colonp;
    10431140
    10441141        if (!filenames)
     
    10771174            if (semip)
    10781175              {
    1079                 unsigned int l = p - variable_buffer;
     1176                unsigned int l = p2 - variable_buffer;
    10801177                *(--semip) = ';';
    10811178                collapse_continuations (semip);
    10821179                variable_buffer_output (p2 + strlen (p2),
    10831180                                        semip, strlen (semip)+1);
    1084                 p = variable_buffer + l;
     1181                p2 = variable_buffer + l;
    10851182              }
    10861183            record_target_var (filenames, p2,
     
    10931190        /* This is a normal target, _not_ a target-specific variable.
    10941191           Unquote any = in the dependency list.  */
    1095         find_char_unquote (lb_next, '=', 0, 0, 0);
     1192        find_char_unquote (lb_next, MAP_EQUALS);
     1193
     1194        /* Remember the command prefix for this target.  */
     1195        prefix = cmd_prefix;
    10961196
    10971197        /* We have some targets, so don't ignore the following commands.  */
     
    11081208            if (cmdleft == 0)
    11091209              {
    1110                 cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
     1210                cmdleft = find_char_unquote (p2, MAP_SEMI);
    11111211                if (cmdleft != 0)
    11121212                  *(cmdleft++) = '\0';
     
    11141214          }
    11151215
    1116         /* Is this a static pattern rule: `target: %targ: %dep; ...'?  */
     1216        /* Is this a static pattern rule: 'target: %targ: %dep; ...'?  */
    11171217        p = strchr (p2, ':');
    11181218        while (p != 0 && p[-1] == '\\')
     
    11401240           OR a space around the :.
    11411241        */
    1142         if (p && !(isspace ((unsigned char)p[1]) || !p[1]
    1143                    || isspace ((unsigned char)p[-1])))
     1242        if (p && !(ISSPACE (p[1]) || !p[1] || ISSPACE (p[-1])))
    11441243          p = 0;
    11451244#endif
     
    11621261          {
    11631262            struct nameseq *target;
    1164             target = PARSE_FILE_SEQ (&p2, struct nameseq, ':', NULL,
     1263            target = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_COLON, NULL,
    11651264                                     PARSEFS_NOGLOB);
    11661265            ++p2;
    11671266            if (target == 0)
    1168               fatal (fstart, _("missing target pattern"));
     1267              O (fatal, fstart, _("missing target pattern"));
    11691268            else if (target->next != 0)
    1170               fatal (fstart, _("multiple target patterns"));
     1269              O (fatal, fstart, _("multiple target patterns"));
    11711270            pattern_percent = find_percent_cached (&target->name);
    11721271            pattern = target->name;
    11731272            if (pattern_percent == 0)
    1174               fatal (fstart, _("target pattern contains no `%%'"));
     1273              O (fatal, fstart, _("target pattern contains no '%%'"));
    11751274            free_ns (target);
    11761275          }
     
    12251324        if (set_default && default_goal_var->value[0] == '\0')
    12261325          {
    1227             const char *name;
    12281326            struct dep *d;
    12291327            struct nameseq *t = filenames;
     
    12321330              {
    12331331                int reject = 0;
    1234                 name = t->name;
     1332                const char *name = t->name;
    12351333
    12361334                /* We have nothing to do if this is an implicit rule. */
     
    12381336                  break;
    12391337
    1240                 /* See if this target's name does not start with a `.',
     1338                /* See if this target's name does not start with a '.',
    12411339                   unless it contains a slash.  */
    12421340                if (*name == '.' && strchr (name, '/') == 0
     
    12871385
    12881386      /* We get here except in the case that we just read a rule line.
    1289          Record now the last rule we read, so following spurious
    1290          commands are properly diagnosed.  */
    1291  rule_complete:
     1387         Record now the last rule we read, so following spurious
     1388         commands are properly diagnosed.  */
    12921389      record_waiting_files ();
    12931390    }
    12941391
    1295 #undef  word1eq
     1392#undef word1eq
    12961393
    12971394  if (conditionals->if_cmds)
    1298     fatal (fstart, _("missing `endif'"));
     1395    O (fatal, fstart, _("missing 'endif'"));
    12991396
    13001397  /* At eof, record the last rule.  */
    13011398  record_waiting_files ();
    13021399
    1303   if (collapsed)
    1304     free (collapsed);
     1400  free (collapsed);
    13051401  free (commands);
    13061402}
     
    13161412  char *comment;
    13171413
    1318   comment = find_char_unquote (line, '#', 0, 0, 0);
     1414  comment = find_char_unquote (line, MAP_COMMENT);
    13191415
    13201416  if (comment != 0)
     
    13231419}
    13241420
    1325 /* Execute a `undefine' directive.
     1421/* Execute a 'undefine' directive.
    13261422   The undefine line has already been read, and NAME is the name of
    13271423   the variable to be undefined. */
     
    13361432  name = next_token (var);
    13371433  if (*name == '\0')
    1338     fatal (&ebuf->floc, _("empty variable name"));
     1434    O (fatal, &ebuf->floc, _("empty variable name"));
    13391435  p = name + strlen (name) - 1;
    1340   while (p > name && isblank ((unsigned char)*p))
     1436  while (p > name && ISBLANK (*p))
    13411437    --p;
    13421438  p[1] = '\0';
     
    13461442}
    13471443
    1348 /* Execute a `define' directive.
     1444/* Execute a 'define' directive.
    13491445   The first line has already been read, and NAME is the name of
    13501446   the variable to be defined.  The following lines remain to be read.  */
     
    13541450{
    13551451  struct variable *v;
    1356   enum variable_flavor flavor;
    1357   struct floc defstart;
     1452  struct variable var;
     1453  floc defstart;
    13581454  int nlevels = 1;
    13591455  unsigned int length = 100;
    13601456  char *definition = xmalloc (length);
    13611457  unsigned int idx = 0;
    1362   char *p, *var;
     1458  char *p, *n;
    13631459
    13641460  defstart = ebuf->floc;
    13651461
    1366   p = parse_variable_definition (name, &flavor);
     1462  p = parse_variable_definition (name, &var);
    13671463  if (p == NULL)
    13681464    /* No assignment token, so assume recursive.  */
    1369     flavor = f_recursive;
     1465    var.flavor = f_recursive;
    13701466  else
    13711467    {
    1372       if (*(next_token (p)) != '\0')
    1373         error (&defstart, _("extraneous text after `define' directive"));
     1468      if (var.value[0] != '\0')
     1469        O (error, &defstart, _("extraneous text after 'define' directive"));
    13741470
    13751471      /* Chop the string before the assignment token to get the name.  */
    1376       p[flavor == f_recursive ? -1 : -2] = '\0';
     1472      var.name[var.length] = '\0';
    13771473    }
    13781474
    13791475  /* Expand the variable name and find the beginning (NAME) and end.  */
    1380   var = allocated_variable_expand (name);
    1381   name = next_token (var);
    1382   if (*name == '\0')
    1383     fatal (&defstart, _("empty variable name"));
     1476  n = allocated_variable_expand (name);
     1477  name = next_token (n);
     1478  if (name[0] == '\0')
     1479    O (fatal, &defstart, _("empty variable name"));
    13841480  p = name + strlen (name) - 1;
    1385   while (p > name && isblank ((unsigned char)*p))
     1481  while (p > name && ISBLANK (*p))
    13861482    --p;
    13871483  p[1] = '\0';
     
    13961492      /* If there is nothing left to be eval'd, there's no 'endef'!!  */
    13971493      if (nlines < 0)
    1398         fatal (&defstart, _("missing `endef', unterminated `define'"));
     1494        O (fatal, &defstart, _("missing 'endef', unterminated 'define'"));
    13991495
    14001496      ebuf->floc.lineno += nlines;
     
    14111507
    14121508          /* If this is another 'define', increment the level count.  */
    1413           if ((len == 6 || (len > 6 && isblank ((unsigned char)p[6])))
     1509          if ((len == 6 || (len > 6 && ISBLANK (p[6])))
    14141510              && strneq (p, "define", 6))
    14151511            ++nlevels;
     
    14171513          /* If this is an 'endef', decrement the count.  If it's now 0,
    14181514             we've found the last one.  */
    1419           else if ((len == 5 || (len > 5 && isblank ((unsigned char)p[5])))
     1515          else if ((len == 5 || (len > 5 && ISBLANK (p[5])))
    14201516                   && strneq (p, "endef", 5))
    14211517            {
     
    14231519              remove_comments (p);
    14241520              if (*(next_token (p)) != '\0')
    1425                 error (&ebuf->floc,
    1426                        _("extraneous text after `endef' directive"));
     1521                O (error, &ebuf->floc,
     1522                   _("extraneous text after 'endef' directive"));
    14271523
    14281524              if (--nlevels == 0)
     
    14511547    definition[idx - 1] = '\0';
    14521548
    1453   v = do_variable_definition (&defstart, name, definition, origin, flavor, 0);
     1549  v = do_variable_definition (&defstart, name,
     1550                              definition, origin, var.flavor, 0);
    14541551  free (definition);
    1455   free (var);
     1552  free (n);
    14561553  return (v);
    14571554}
     
    14711568
    14721569static int
    1473 conditional_line (char *line, int len, const struct floc *flocp)
     1570conditional_line (char *line, int len, const floc *flocp)
    14741571{
    1475   char *cmdname;
     1572  const char *cmdname;
    14761573  enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, c_else, c_endif } cmdtype;
    14771574  unsigned int i;
     
    14791576
    14801577  /* Compare a word, both length and contents. */
    1481 #define word1eq(s)      (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))
    1482 #define chkword(s, t)   if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
     1578#define word1eq(s)      (len == CSTRLEN (s) && strneq (s, line, CSTRLEN (s)))
     1579#define chkword(s, t)   if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
    14831580
    14841581  /* Make sure this line is a conditional.  */
     
    14931590
    14941591  /* Found one: skip past it and any whitespace after it.  */
    1495   line = next_token (line + len);
    1496 
    1497 #define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname)
     1592  line += len;
     1593  NEXT_TOKEN (line);
     1594
     1595#define EXTRATEXT() OS (error, flocp, _("extraneous text after '%s' directive"), cmdname)
     1596#define EXTRACMD()  OS (fatal, flocp, _("extraneous '%s'"), cmdname)
    14981597
    14991598  /* An 'endif' cannot contain extra text, and reduces the if-depth by 1  */
     
    15011600    {
    15021601      if (*line != '\0')
    1503         EXTRANEOUS ();
     1602        EXTRATEXT ();
    15041603
    15051604      if (!conditionals->if_cmds)
    1506         fatal (flocp, _("extraneous `%s'"), cmdname);
     1605        EXTRACMD ();
    15071606
    15081607      --conditionals->if_cmds;
     
    15181617
    15191618      if (!conditionals->if_cmds)
    1520         fatal (flocp, _("extraneous `%s'"), cmdname);
     1619        EXTRACMD ();
    15211620
    15221621      o = conditionals->if_cmds - 1;
    15231622
    15241623      if (conditionals->seen_else[o])
    1525         fatal (flocp, _("only one `else' per conditional"));
     1624        O (fatal, flocp, _("only one 'else' per conditional"));
    15261625
    15271626      /* Change the state of ignorance.  */
     
    15491648
    15501649      /* Find the length of the next word.  */
    1551       for (p = line+1; *p != '\0' && !isspace ((unsigned char)*p); ++p)
     1650      for (p = line+1; ! STOP_SET (*p, MAP_SPACE|MAP_NUL); ++p)
    15521651        ;
    15531652      len = p - line;
    15541653
    15551654      /* If it's 'else' or 'endif' or an illegal conditional, fail.  */
    1556       if (word1eq("else") || word1eq("endif")
     1655      if (word1eq ("else") || word1eq ("endif")
    15571656          || conditional_line (line, len, flocp) < 0)
    1558         EXTRANEOUS ();
     1657        EXTRATEXT ();
    15591658      else
    15601659        {
     
    15861685    }
    15871686
    1588   /* Record that we have seen an `if...' but no `else' so far.  */
     1687  /* Record that we have seen an 'if...' but no 'else' so far.  */
    15891688  conditionals->seen_else[o] = 0;
    15901689
     
    15931692    if (conditionals->ignoring[i])
    15941693      {
    1595         /* We are already ignoring, so just push a level to match the next
    1596            "else" or "endif", and keep ignoring.  We don't want to expand
    1597            variables in the condition.  */
    1598         conditionals->ignoring[o] = 1;
    1599         return 1;
     1694        /* We are already ignoring, so just push a level to match the next
     1695           "else" or "endif", and keep ignoring.  We don't want to expand
     1696           variables in the condition.  */
     1697        conditionals->ignoring[o] = 1;
     1698        return 1;
    16001699      }
    16011700
     
    16131712      p = end_of_token (var);
    16141713      i = p - var;
    1615       p = next_token (p);
     1714      NEXT_TOKEN (p);
    16161715      if (*p != '\0')
    1617         return -1;
     1716        return -1;
    16181717
    16191718      var[i] = '\0';
     
    16331732
    16341733      if (termin != ',' && termin != '"' && termin != '\'')
    1635         return -1;
     1734        return -1;
    16361735
    16371736      s1 = ++line;
    16381737      /* Find the end of the first string.  */
    16391738      if (termin == ',')
    1640         {
    1641           int count = 0;
    1642           for (; *line != '\0'; ++line)
    1643             if (*line == '(')
    1644               ++count;
    1645             else if (*line == ')')
    1646               --count;
    1647             else if (*line == ',' && count <= 0)
    1648               break;
    1649         }
     1739        {
     1740          int count = 0;
     1741          for (; *line != '\0'; ++line)
     1742            if (*line == '(')
     1743              ++count;
     1744            else if (*line == ')')
     1745              --count;
     1746            else if (*line == ',' && count <= 0)
     1747              break;
     1748        }
    16501749      else
    1651         while (*line != '\0' && *line != termin)
    1652           ++line;
     1750        while (*line != '\0' && *line != termin)
     1751          ++line;
    16531752
    16541753      if (*line == '\0')
    1655         return -1;
     1754        return -1;
    16561755
    16571756      if (termin == ',')
    1658         {
    1659           /* Strip blanks after the first string.  */
    1660           char *p = line++;
    1661           while (isblank ((unsigned char)p[-1]))
    1662             --p;
    1663           *p = '\0';
    1664         }
     1757        {
     1758          /* Strip blanks after the first string.  */
     1759          char *p = line++;
     1760          while (ISBLANK (p[-1]))
     1761            --p;
     1762          *p = '\0';
     1763        }
    16651764      else
    1666         *line++ = '\0';
     1765        *line++ = '\0';
    16671766
    16681767      s2 = variable_expand (s1);
    16691768      /* We must allocate a new copy of the expanded string because
    1670         variable_expand re-uses the same buffer.  */
     1769        variable_expand re-uses the same buffer.  */
    16711770      l = strlen (s2);
    16721771      s1 = alloca (l + 1);
     
    16741773
    16751774      if (termin != ',')
    1676         /* Find the start of the second string.  */
    1677         line = next_token (line);
     1775        /* Find the start of the second string.  */
     1776        NEXT_TOKEN (line);
    16781777
    16791778      termin = termin == ',' ? ')' : *line;
    16801779      if (termin != ')' && termin != '"' && termin != '\'')
    1681         return -1;
     1780        return -1;
    16821781
    16831782      /* Find the end of the second string.  */
    16841783      if (termin == ')')
    1685         {
    1686           int count = 0;
    1687           s2 = next_token (line);
    1688           for (line = s2; *line != '\0'; ++line)
    1689             {
    1690               if (*line == '(')
    1691                 ++count;
    1692               else if (*line == ')')
    1693                 {
    1694                   if (count <= 0)
    1695                     break;
    1696                   else
    1697                     --count;
    1698                 }
    1699             }
    1700         }
     1784        {
     1785          int count = 0;
     1786          s2 = next_token (line);
     1787          for (line = s2; *line != '\0'; ++line)
     1788            {
     1789              if (*line == '(')
     1790                ++count;
     1791              else if (*line == ')')
     1792                {
     1793                  if (count <= 0)
     1794                    break;
     1795                  else
     1796                    --count;
     1797                }
     1798            }
     1799        }
    17011800      else
    1702         {
    1703           ++line;
    1704           s2 = line;
    1705           while (*line != '\0' && *line != termin)
    1706             ++line;
    1707         }
     1801        {
     1802          ++line;
     1803          s2 = line;
     1804          while (*line != '\0' && *line != termin)
     1805            ++line;
     1806        }
    17081807
    17091808      if (*line == '\0')
    1710         return -1;
    1711 
    1712       *line = '\0';
    1713       line = next_token (++line);
     1809        return -1;
     1810
     1811      *(line++) = '\0';
     1812      NEXT_TOKEN (line);
    17141813      if (*line != '\0')
    1715         EXTRANEOUS ();
     1814        EXTRATEXT ();
    17161815
    17171816      s2 = variable_expand (s2);
     
    17411840record_target_var (struct nameseq *filenames, char *defn,
    17421841                   enum variable_origin origin, struct vmodifiers *vmod,
    1743                    const struct floc *flocp)
     1842                   const floc *flocp)
    17441843{
    17451844  struct nameseq *nextf;
     
    17551854      struct variable *v;
    17561855      const char *name = filenames->name;
    1757       const char *fname;
    17581856      const char *percent;
    17591857      struct pattern_var *p;
     
    17801878          else
    17811879            v->value = xstrdup (v->value);
    1782 
    1783           fname = p->target;
    17841880        }
    17851881      else
     
    17981894
    17991895          initialize_file_variables (f, 1);
    1800           fname = f->name;
    18011896
    18021897          current_variable_set_list = f->variables;
    18031898          v = try_variable_definition (flocp, defn, origin, 1);
    18041899          if (!v)
    1805             fatal (flocp, _("Malformed target-specific variable definition"));
     1900            O (fatal, flocp, _("Malformed target-specific variable definition"));
    18061901          current_variable_set_list = global;
    18071902        }
     
    18171912        {
    18181913          struct variable *gv;
    1819           int len = strlen(v->name);
     1914          int len = strlen (v->name);
    18201915
    18211916          gv = lookup_variable (v->name, len);
    1822           if (gv && (gv->origin == o_env_override || gv->origin == o_command))
     1917          if (gv && v != gv
     1918              && (gv->origin == o_env_override || gv->origin == o_command))
    18231919            {
    1824               if (v->value != 0)
    1825                 free (v->value);
     1920              free (v->value);
    18261921              v->value = xstrdup (gv->value);
    18271922              v->origin = gv->origin;
     
    18381933   by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
    18391934   TWO_COLON is nonzero if a double colon was used.
    1840    If not nil, PATTERN is the `%' pattern to make this
     1935   If not nil, PATTERN is the '%' pattern to make this
    18411936   a static pattern rule, and PATTERN_PERCENT is a pointer
    1842    to the `%' within it.
     1937   to the '%' within it.
    18431938
    18441939   The links of FILENAMES are freed, and so are any names in it
     
    18501945              unsigned int cmds_started, char *commands,
    18511946              unsigned int commands_idx, int two_colon,
    1852               const struct floc *flocp)
     1947              char prefix, const floc *flocp)
    18531948{
    18541949  struct commands *cmds;
     
    18621957     See Savannah bug # 12124.  */
    18631958  if (snapped_deps)
    1864     fatal (flocp, _("prerequisites cannot be defined in recipes"));
     1959    O (fatal, flocp, _("prerequisites cannot be defined in recipes"));
    18651960
    18661961  /* Determine if this is a pattern rule or not.  */
     
    18741969      cmds->fileinfo.filenm = flocp->filenm;
    18751970      cmds->fileinfo.lineno = cmds_started;
     1971      cmds->fileinfo.offset = 0;
    18761972      cmds->commands = xstrndup (commands, commands_idx);
    18771973      cmds->command_lines = 0;
     1974      cmds->recipe_prefix = prefix;
    18781975    }
    18791976  else
     
    18841981  if (depstr == 0)
    18851982    deps = 0;
    1886   else if (second_expansion && strchr (depstr, '$'))
    1887     {
    1888       deps = alloc_dep ();
    1889       deps->name = depstr;
    1890       deps->need_2nd_expansion = 1;
    1891       deps->staticpattern = pattern != 0;
    1892     }
    18931983  else
    18941984    {
    1895       deps = split_prereqs (depstr);
    1896       free (depstr);
    1897 
    1898       /* We'll enter static pattern prereqs later when we have the stem.  We
    1899          don't want to enter pattern rules at all so that we don't think that
    1900          they ought to exist (make manual "Implicit Rule Search Algorithm",
    1901          item 5c).  */
    1902       if (! pattern && ! implicit_percent)
    1903         deps = enter_prereqs (deps, NULL);
     1985      depstr = unescape_char (depstr, ':');
     1986      if (second_expansion && strchr (depstr, '$'))
     1987        {
     1988          deps = alloc_dep ();
     1989          deps->name = depstr;
     1990          deps->need_2nd_expansion = 1;
     1991          deps->staticpattern = pattern != 0;
     1992        }
     1993      else
     1994        {
     1995          deps = split_prereqs (depstr);
     1996          free (depstr);
     1997
     1998          /* We'll enter static pattern prereqs later when we have the stem.
     1999             We don't want to enter pattern rules at all so that we don't
     2000             think that they ought to exist (make manual "Implicit Rule Search
     2001             Algorithm", item 5c).  */
     2002          if (! pattern && ! implicit_percent)
     2003            deps = enter_prereqs (deps, NULL);
     2004        }
    19042005    }
    19052006
     
    19152016
    19162017      if (pattern != 0)
    1917         fatal (flocp, _("mixed implicit and static pattern rules"));
     2018        O (fatal, flocp, _("mixed implicit and static pattern rules"));
    19182019
    19192020      /* Count the targets to create an array of target names.
     
    19382039
    19392040          if (implicit_percent == 0)
    1940             fatal (flocp, _("mixed implicit and normal rules"));
    1941 
    1942           targets[c] = name;
    1943           target_pats[c] = implicit_percent;
     2041            O (fatal, flocp, _("mixed implicit and normal rules"));
     2042
     2043          targets[c] = name;
     2044          target_pats[c] = implicit_percent;
    19442045          ++c;
    19452046
     
    19712072          posix_pedantic = 1;
    19722073          define_variable_cname (".SHELLFLAGS", "-ec", o_default, 0);
     2074          /* These default values are based on IEEE Std 1003.1-2008.  */
     2075          define_variable_cname ("ARFLAGS", "-rv", o_default, 0);
     2076          define_variable_cname ("CC", "c99", o_default, 0);
     2077          define_variable_cname ("CFLAGS", "-O", o_default, 0);
     2078          define_variable_cname ("FC", "fort77", o_default, 0);
     2079          define_variable_cname ("FFLAGS", "-O 1", o_default, 0);
     2080          define_variable_cname ("SCCSGETFLAGS", "-s", o_default, 0);
    19732081        }
    19742082      else if (streq (name, ".SECONDEXPANSION"))
    19752083        second_expansion = 1;
    1976 #if !defined(WINDOWS32) && !defined (__MSDOS__) && !defined (__EMX__)
     2084#if !defined (__MSDOS__) && !defined (__EMX__)
    19772085      else if (streq (name, ".ONESHELL"))
    19782086        one_shell = 1;
     
    19802088
    19812089      /* If this is a static pattern rule:
    1982          `targets: target%pattern: prereq%pattern; recipe',
     2090         'targets: target%pattern: prereq%pattern; recipe',
    19832091         make sure the pattern matches this target name.  */
    19842092      if (pattern && !pattern_matches (pattern, pattern_percent, name))
    1985         error (flocp, _("target `%s' doesn't match the target pattern"), name);
     2093        OS (error, flocp,
     2094            _("target '%s' doesn't match the target pattern"), name);
    19862095      else if (deps)
    19872096        /* If there are multiple targets, copy the chain DEPS for all but the
     
    19922101      /* Find or create an entry in the file database for this target.  */
    19932102      if (!two_colon)
    1994         {
    1995           /* Single-colon.  Combine this rule with the file's existing record,
    1996              if any.  */
    1997           f = enter_file (strcache_add (name));
    1998           if (f->double_colon)
    1999             fatal (flocp,
    2000                    _("target file `%s' has both : and :: entries"), f->name);
    2001 
    2002           /* If CMDS == F->CMDS, this target was listed in this rule
    2003              more than once.  Just give a warning since this is harmless.  */
    2004           if (cmds != 0 && cmds == f->cmds)
    2005             error (flocp,
    2006                    _("target `%s' given more than once in the same rule."),
    2007                    f->name);
    2008 
    2009           /* Check for two single-colon entries both with commands.
    2010              Check is_target so that we don't lose on files such as .c.o
    2011              whose commands were preinitialized.  */
    2012           else if (cmds != 0 && f->cmds != 0 && f->is_target)
    2013             {
    2014               error (&cmds->fileinfo,
    2015                      _("warning: overriding recipe for target `%s'"),
     2103        {
     2104          /* Single-colon.  Combine this rule with the file's existing record,
     2105             if any.  */
     2106          f = enter_file (strcache_add (name));
     2107          if (f->double_colon)
     2108            OS (fatal, flocp,
     2109                _("target file '%s' has both : and :: entries"), f->name);
     2110
     2111          /* If CMDS == F->CMDS, this target was listed in this rule
     2112             more than once.  Just give a warning since this is harmless.  */
     2113          if (cmds != 0 && cmds == f->cmds)
     2114            OS (error, flocp,
     2115                _("target '%s' given more than once in the same rule"),
     2116                f->name);
     2117
     2118          /* Check for two single-colon entries both with commands.
     2119             Check is_target so that we don't lose on files such as .c.o
     2120             whose commands were preinitialized.  */
     2121          else if (cmds != 0 && f->cmds != 0 && f->is_target)
     2122            {
     2123              size_t l = strlen (f->name);
     2124              error (&cmds->fileinfo, l,
     2125                     _("warning: overriding recipe for target '%s'"),
    20162126                     f->name);
    2017               error (&f->cmds->fileinfo,
    2018                      _("warning: ignoring old recipe for target `%s'"),
     2127              error (&f->cmds->fileinfo, l,
     2128                     _("warning: ignoring old recipe for target '%s'"),
    20192129                     f->name);
    2020             }
    2021 
    2022           /* Defining .DEFAULT with no deps or cmds clears it.  */
    2023           if (f == default_file && this == 0 && cmds == 0)
    2024             f->cmds = 0;
    2025           if (cmds != 0)
    2026             f->cmds = cmds;
    2027 
    2028           /* Defining .SUFFIXES with no dependencies clears out the list of
    2029              suffixes.  */
    2030           if (f == suffix_file && this == 0)
    2031             {
     2130            }
     2131
     2132          /* Defining .DEFAULT with no deps or cmds clears it.  */
     2133          if (f == default_file && this == 0 && cmds == 0)
     2134            f->cmds = 0;
     2135          if (cmds != 0)
     2136            f->cmds = cmds;
     2137
     2138          /* Defining .SUFFIXES with no dependencies clears out the list of
     2139             suffixes.  */
     2140          if (f == suffix_file && this == 0)
     2141            {
    20322142              free_dep_chain (f->deps);
    2033               f->deps = 0;
    2034             }
    2035         }
     2143              f->deps = 0;
     2144            }
     2145        }
    20362146      else
    2037         {
    2038           /* Double-colon.  Make a new record even if there already is one.  */
    2039           f = lookup_file (name);
    2040 
    2041           /* Check for both : and :: rules.  Check is_target so we don't lose
    2042              on default suffix rules or makefiles.  */
    2043           if (f != 0 && f->is_target && !f->double_colon)
    2044             fatal (flocp,
    2045                    _("target file `%s' has both : and :: entries"), f->name);
    2046 
    2047           f = enter_file (strcache_add (name));
    2048           /* If there was an existing entry and it was a double-colon entry,
    2049              enter_file will have returned a new one, making it the prev
    2050              pointer of the old one, and setting its double_colon pointer to
    2051              the first one.  */
    2052           if (f->double_colon == 0)
    2053             /* This is the first entry for this name, so we must set its
    2054                double_colon pointer to itself.  */
    2055             f->double_colon = f;
    2056 
    2057           f->cmds = cmds;
    2058         }
     2147        {
     2148          /* Double-colon.  Make a new record even if there already is one.  */
     2149          f = lookup_file (name);
     2150
     2151          /* Check for both : and :: rules.  Check is_target so we don't lose
     2152             on default suffix rules or makefiles.  */
     2153          if (f != 0 && f->is_target && !f->double_colon)
     2154            OS (fatal, flocp,
     2155                _("target file '%s' has both : and :: entries"), f->name);
     2156
     2157          f = enter_file (strcache_add (name));
     2158          /* If there was an existing entry and it was a double-colon entry,
     2159             enter_file will have returned a new one, making it the prev
     2160             pointer of the old one, and setting its double_colon pointer to
     2161             the first one.  */
     2162          if (f->double_colon == 0)
     2163            /* This is the first entry for this name, so we must set its
     2164               double_colon pointer to itself.  */
     2165            f->double_colon = f;
     2166
     2167          f->cmds = cmds;
     2168        }
    20592169
    20602170      f->is_target = 1;
    20612171
    20622172      /* If this is a static pattern rule, set the stem to the part of its
    2063          name that matched the `%' in the pattern, so you can use $* in the
     2173         name that matched the '%' in the pattern, so you can use $* in the
    20642174         commands.  If we didn't do it before, enter the prereqs now.  */
    20652175      if (pattern)
     
    21192229      name = filenames->name;
    21202230      if (find_percent_cached (&name))
    2121         fatal (flocp, _("mixed implicit and normal rules"));
     2231        O (error, flocp,
     2232           _("*** mixed implicit and normal rules: deprecated syntax"));
    21222233    }
    21232234}
     
    21342245
    21352246static char *
    2136 find_char_unquote (char *string, int stop1, int stop2, int blank,
    2137                    int ignorevars)
     2247find_char_unquote (char *string, int map)
    21382248{
    21392249  unsigned int string_len = 0;
    21402250  char *p = string;
    21412251
    2142   if (ignorevars)
    2143     ignorevars = '$';
     2252  /* Always stop on NUL.  */
     2253  map |= MAP_NUL;
    21442254
    21452255  while (1)
    21462256    {
    2147       if (stop2 && blank)
    2148         while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2
    2149                && ! isblank ((unsigned char) *p))
    2150           ++p;
    2151       else if (stop2)
    2152         while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2)
    2153           ++p;
    2154       else if (blank)
    2155         while (*p != '\0' && *p != ignorevars && *p != stop1
    2156                && ! isblank ((unsigned char) *p))
    2157           ++p;
    2158       else
    2159         while (*p != '\0' && *p != ignorevars && *p != stop1)
    2160           ++p;
     2257      while (! STOP_SET (*p, map))
     2258        ++p;
    21612259
    21622260      if (*p == '\0')
    2163         break;
     2261        break;
    21642262
    21652263      /* If we stopped due to a variable reference, skip over its contents.  */
    2166       if (*p == ignorevars)
     2264      if (STOP_SET (*p, MAP_VARIABLE))
    21672265        {
    21682266          char openparen = p[1];
     2267
     2268          /* Check if '$' is the last character in the string.  */
     2269          if (openparen == '\0')
     2270            break;
    21692271
    21702272          p += 2;
     
    21952297
    21962298      if (p > string && p[-1] == '\\')
    2197         {
    2198           /* Search for more backslashes.  */
    2199           int i = -2;
    2200           while (&p[i] >= string && p[i] == '\\')
    2201             --i;
    2202           ++i;
    2203           /* Only compute the length if really needed.  */
    2204           if (string_len == 0)
    2205             string_len = strlen (string);
    2206           /* The number of backslashes is now -I.
    2207              Copy P over itself to swallow half of them.  */
    2208           memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1);
    2209           p += i/2;
    2210           if (i % 2 == 0)
    2211             /* All the backslashes quoted each other; the STOPCHAR was
    2212                unquoted.  */
    2213             return p;
    2214 
    2215           /* The STOPCHAR was quoted by a backslash.  Look for another.  */
    2216         }
     2299        {
     2300          /* Search for more backslashes.  */
     2301          int i = -2;
     2302          while (&p[i] >= string && p[i] == '\\')
     2303            --i;
     2304          ++i;
     2305          /* Only compute the length if really needed.  */
     2306          if (string_len == 0)
     2307            string_len = strlen (string);
     2308          /* The number of backslashes is now -I.
     2309             Copy P over itself to swallow half of them.  */
     2310          memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1);
     2311          p += i/2;
     2312          if (i % 2 == 0)
     2313            /* All the backslashes quoted each other; the STOPCHAR was
     2314               unquoted.  */
     2315            return p;
     2316
     2317          /* The STOPCHAR was quoted by a backslash.  Look for another.  */
     2318        }
    22172319      else
    2218         /* No backslash in sight.  */
    2219         return p;
     2320        /* No backslash in sight.  */
     2321        return p;
    22202322    }
    22212323
     
    22242326}
    22252327
     2328/* Unescape a character in a string.  The string is compressed onto itself.  */
     2329
     2330static char *
     2331unescape_char (char *string, int c)
     2332{
     2333  char *p = string;
     2334  char *s = string;
     2335
     2336  while (*s != '\0')
     2337    {
     2338      if (*s == '\\')
     2339        {
     2340          char *e = s;
     2341          int l;
     2342
     2343          /* We found a backslash.  See if it's escaping our character.  */
     2344          while (*e == '\\')
     2345            ++e;
     2346          l = e - s;
     2347
     2348          if (*e != c || l%2 == 0)
     2349            {
     2350              /* It's not; just take it all without unescaping.  */
     2351              memmove (p, s, l);
     2352              p += l;
     2353
     2354              // If we hit the end of the string, we're done
     2355              if (*e == '\0')
     2356                break;
     2357            }
     2358          else if (l > 1)
     2359            {
     2360              /* It is, and there's >1 backslash.  Take half of them.  */
     2361              l /= 2;
     2362              memmove (p, s, l);
     2363              p += l;
     2364            }
     2365
     2366          s = e;
     2367        }
     2368
     2369      *(p++) = *(s++);
     2370    }
     2371
     2372  *p = '\0';
     2373  return string;
     2374}
     2375
    22262376/* Search PATTERN for an unquoted % and handle quoting.  */
    22272377
     
    22292379find_percent (char *pattern)
    22302380{
    2231   return find_char_unquote (pattern, '%', 0, 0, 0);
     2381  return find_char_unquote (pattern, MAP_PERCENT);
    22322382}
    22332383
     
    22522402  while (1)
    22532403    {
    2254       while (*p != '\0' && *p != '%')
     2404      while (! STOP_SET (*p, MAP_PERCENT|MAP_NUL))
    22552405        ++p;
    22562406
     
    23222472 */
    23232473
    2324 static unsigned long
     2474static long
    23252475readstring (struct ebuffer *ebuf)
    23262476{
     
    23942544      len = strlen (p);
    23952545      if (len == 0)
    2396         {
    2397           /* This only happens when the first thing on the line is a '\0'.
    2398              It is a pretty hopeless case, but (wonder of wonders) Athena
    2399              lossage strikes again!  (xmkmf puts NULs in its makefiles.)
    2400              There is nothing really to be done; we synthesize a newline so
    2401              the following line doesn't appear to be part of this line.  */
    2402           error (&ebuf->floc,
    2403                  _("warning: NUL character seen; rest of line ignored"));
    2404           p[0] = '\n';
    2405           len = 1;
    2406         }
     2546        {
     2547          /* This only happens when the first thing on the line is a '\0'.
     2548             It is a pretty hopeless case, but (wonder of wonders) Athena
     2549             lossage strikes again!  (xmkmf puts NULs in its makefiles.)
     2550             There is nothing really to be done; we synthesize a newline so
     2551             the following line doesn't appear to be part of this line.  */
     2552          O (error, &ebuf->floc,
     2553             _("warning: NUL character seen; rest of line ignored"));
     2554          p[0] = '\n';
     2555          len = 1;
     2556        }
    24072557
    24082558      /* Jump past the text we just read.  */
     
    24232573        {
    24242574          --p;
    2425           p[-1] = '\n';
     2575          memmove (p-1, p, strlen (p) + 1);
    24262576        }
    24272577#endif
     
    24292579      backslash = 0;
    24302580      for (p2 = p - 2; p2 >= start; --p2)
    2431         {
    2432           if (*p2 != '\\')
    2433             break;
     2581        {
     2582          if (*p2 != '\\')
     2583            break;
    24342584          backslash = !backslash;
    2435         }
     2585        }
    24362586
    24372587      if (!backslash)
    2438         {
    2439           p[-1] = '\0';
    2440           break;
    2441         }
     2588        {
     2589          p[-1] = '\0';
     2590          break;
     2591        }
    24422592
    24432593      /* It was a backslash/newline combo.  If we have more space, read
     
    24832633     w_dcolon       A double-colon
    24842634     w_semicolon    A semicolon
    2485      w_varassign    A variable assignment operator (=, :=, +=, or ?=)
     2635     w_varassign    A variable assignment operator (=, :=, ::=, +=, ?=, or !=)
    24862636
    24872637   Note that this function is only used when reading certain parts of the
     
    24972647
    24982648  /* Skip any leading whitespace.  */
    2499   while (isblank ((unsigned char)*p))
     2649  while (ISBLANK (*p))
    25002650    ++p;
    25012651
     
    25222672        case ':':
    25232673          ++p;
    2524           wtype = w_dcolon;
     2674          if (p[1] != '=')
     2675            wtype = w_dcolon;
     2676          else
     2677            {
     2678              wtype = w_varassign;
     2679              ++p;
     2680            }
    25252681          break;
    25262682
     
    25342690    case '+':
    25352691    case '?':
     2692    case '!':
    25362693      if (*p == '=')
    25372694        {
     
    25532710  /* This is some non-operator word.  A word consists of the longest
    25542711     string of characters that doesn't contain whitespace, one of [:=#],
    2555      or [?+]=, or one of the chars in the DELIM string.  */
     2712     or [?+!]=, or one of the chars in the DELIM string.  */
    25562713
    25572714  /* We start out assuming a static word; if we see a variable we'll
     
    25752732        case ':':
    25762733#ifdef HAVE_DOS_PATHS
    2577           /* A word CAN include a colon in its drive spec.  The drive
    2578              spec is allowed either at the beginning of a word, or as part
    2579              of the archive member name, like in "libfoo.a(d:/foo/bar.o)".  */
    2580           if (!(p - beg >= 2
    2581                 && (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2])
    2582                 && (p - beg == 2 || p[-3] == '(')))
     2734          /* A word CAN include a colon in its drive spec.  The drive
     2735             spec is allowed either at the beginning of a word, or as part
     2736             of the archive member name, like in "libfoo.a(d:/foo/bar.o)".  */
     2737          if (!(p - beg >= 2
     2738                && (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2])
     2739                && (p - beg == 2 || p[-3] == '(')))
    25832740#endif
    2584           goto done_word;
     2741          goto done_word;
    25852742
    25862743        case '$':
     
    25882745          if (c == '$')
    25892746            break;
     2747          if (c == '\0')
     2748            goto done_word;
    25902749
    25912750          /* This is a variable reference, so note that it's expandable.
     
    26572816construct_include_path (const char **arg_dirs)
    26582817{
    2659 #ifdef VAXC             /* just don't ask ... */
     2818#ifdef VAXC             /* just don't ask ... */
    26602819  stat_t stbuf;
    26612820#else
     
    26882847    while (*arg_dirs != 0)
    26892848      {
    2690         const char *dir = *(arg_dirs++);
     2849        const char *dir = *(arg_dirs++);
    26912850        char *expanded = 0;
    26922851        int e;
    26932852
    2694         if (dir[0] == '~')
    2695           {
    2696             expanded = tilde_expand (dir);
    2697             if (expanded != 0)
    2698               dir = expanded;
    2699           }
     2853        if (dir[0] == '~')
     2854          {
     2855            expanded = tilde_expand (dir);
     2856            if (expanded != 0)
     2857              dir = expanded;
     2858          }
    27002859
    27012860        EINTRLOOP (e, stat (dir, &stbuf));
    2702         if (e == 0 && S_ISDIR (stbuf.st_mode))
     2861        if (e == 0 && S_ISDIR (stbuf.st_mode))
    27032862          {
    27042863            unsigned int len = strlen (dir);
     
    27112870          }
    27122871
    2713         if (expanded)
    2714           free (expanded);
     2872        free (expanded);
    27152873      }
    27162874
     
    27262884      {
    27272885        unsigned int len = strlen (djdir->value) + 8;
    2728         char *defdir = alloca (len + 1);
    2729 
    2730         strcat (strcpy (defdir, djdir->value), "/include");
    2731         dirs[idx++] = strcache_add (defdir);
     2886        char *defdir = alloca (len + 1);
     2887
     2888        strcat (strcpy (defdir, djdir->value), "/include");
     2889        dirs[idx++] = strcache_add (defdir);
    27322890
    27332891        if (len > max_incl_len)
     
    27752933  if (name[1] == '/' || name[1] == '\0')
    27762934    {
    2777       extern char *getenv ();
    27782935      char *home_dir;
    27792936      int is_variable;
    27802937
    27812938      {
    2782         /* Turn off --warn-undefined-variables while we expand HOME.  */
    2783         int save = warn_undefined_variables_flag;
    2784         warn_undefined_variables_flag = 0;
    2785 
    2786         home_dir = allocated_variable_expand ("$(HOME)");
    2787 
    2788         warn_undefined_variables_flag = save;
     2939        /* Turn off --warn-undefined-variables while we expand HOME.  */
     2940        int save = warn_undefined_variables_flag;
     2941        warn_undefined_variables_flag = 0;
     2942
     2943        home_dir = allocated_variable_expand ("$(HOME)");
     2944
     2945        warn_undefined_variables_flag = save;
    27892946      }
    27902947
    27912948      is_variable = home_dir[0] != '\0';
    27922949      if (!is_variable)
    2793         {
    2794           free (home_dir);
    2795           home_dir = getenv ("HOME");
    2796         }
     2950        {
     2951          free (home_dir);
     2952          home_dir = getenv ("HOME");
     2953        }
    27972954# if !defined(_AMIGA) && !defined(WINDOWS32)
    27982955      if (home_dir == 0 || home_dir[0] == '\0')
    2799         {
    2800           extern char *getlogin ();
    2801           char *logname = getlogin ();
    2802           home_dir = 0;
    2803           if (logname != 0)
    2804             {
    2805               struct passwd *p = getpwnam (logname);
    2806               if (p != 0)
    2807                 home_dir = p->pw_dir;
    2808             }
    2809         }
     2956        {
     2957          char *logname = getlogin ();
     2958          home_dir = 0;
     2959          if (logname != 0)
     2960            {
     2961              struct passwd *p = getpwnam (logname);
     2962              if (p != 0)
     2963                home_dir = p->pw_dir;
     2964            }
     2965        }
    28102966# endif /* !AMIGA && !WINDOWS32 */
    28112967      if (home_dir != 0)
    2812         {
    2813           char *new = xstrdup (concat (2, home_dir, name + 1));
    2814           if (is_variable)
    2815             free (home_dir);
    2816           return new;
    2817         }
     2968        {
     2969          char *new = xstrdup (concat (2, home_dir, name + 1));
     2970          if (is_variable)
     2971            free (home_dir);
     2972          return new;
     2973        }
    28182974    }
    28192975# if !defined(_AMIGA) && !defined(WINDOWS32)
     
    28232979      char *userend = strchr (name + 1, '/');
    28242980      if (userend != 0)
    2825         *userend = '\0';
     2981        *userend = '\0';
    28262982      pwent = getpwnam (name + 1);
    28272983      if (pwent != 0)
    2828         {
    2829           if (userend == 0)
    2830             return xstrdup (pwent->pw_dir);
    2831           else
    2832             return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1));
    2833         }
     2984        {
     2985          if (userend == 0)
     2986            return xstrdup (pwent->pw_dir);
     2987          else
     2988            return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1));
     2989        }
    28342990      else if (userend != 0)
    2835         *userend = '/';
     2991        *userend = '/';
    28362992    }
    28372993# endif /* !AMIGA && !WINDOWS32 */
     
    28653021
    28663022void *
    2867 parse_file_seq (char **stringp, unsigned int size, int stopchar,
     3023parse_file_seq (char **stringp, unsigned int size, int stopmap,
    28683024                const char *prefix, int flags)
    28693025{
    2870   extern void dir_setup_glob (glob_t *glob);
    2871 
    28723026  /* tmp points to tmpbuf after the prefix, if any.
    28733027     tp is the end of the buffer. */
    28743028  static char *tmpbuf = NULL;
    2875   static int tmpbuf_len = 0;
    2876 
    2877   int cachep = (! (flags & PARSEFS_NOCACHE));
     3029
     3030  int cachep = NONE_SET (flags, PARSEFS_NOCACHE);
    28783031
    28793032  struct nameseq *new = 0;
     
    28903043  char *tp;
    28913044
    2892 #ifdef VMS
    2893 # define VMS_COMMA ','
    2894 #else
    2895 # define VMS_COMMA 0
    2896 #endif
     3045  /* Always stop on NUL.  */
     3046  stopmap |= MAP_NUL;
    28973047
    28983048  if (size < sizeof (struct nameseq))
    28993049    size = sizeof (struct nameseq);
    29003050
    2901   if (! (flags & PARSEFS_NOGLOB))
     3051  if (NONE_SET (flags, PARSEFS_NOGLOB))
    29023052    dir_setup_glob (&gl);
    29033053
    29043054  /* Get enough temporary space to construct the largest possible target.  */
    29053055  {
     3056    static int tmpbuf_len = 0;
    29063057    int l = strlen (*stringp) + 1;
    29073058    if (l > tmpbuf_len)
     
    29203071      const char **nlist = 0;
    29213072      char *tildep = 0;
     3073      int globme = 1;
    29223074#ifndef NO_ARCHIVES
    29233075      char *arname = 0;
     
    29293081
    29303082      /* Skip whitespace; at the end of the string or STOPCHAR we're done.  */
    2931       p = next_token (p);
    2932       if (*p == '\0' || *p == stopchar)
    2933         break;
     3083      NEXT_TOKEN (p);
     3084      if (STOP_SET (*p, stopmap))
     3085        break;
    29343086
    29353087      /* There are names left, so find the end of the next name.
    29363088         Throughout this iteration S points to the start.  */
    29373089      s = p;
    2938       p = find_char_unquote (p, stopchar, VMS_COMMA, 1, 0);
     3090      p = find_char_unquote (p, stopmap|MAP_VMSCOMMA|MAP_BLANK);
    29393091#ifdef VMS
    2940         /* convert comma separated list to space separated */
     3092        /* convert comma separated list to space separated */
    29413093      if (p && *p == ',')
    2942         *p =' ';
     3094        *p =' ';
    29433095#endif
    29443096#ifdef _AMIGA
    2945       if (stopchar == ':' && p && *p == ':'
    2946           && !(isspace ((unsigned char)p[1]) || !p[1]
    2947                || isspace ((unsigned char)p[-1])))
    2948         p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0);
     3097      if (p && STOP_SET (*p, stopmap & MAP_COLON)
     3098          && !(ISSPACE (p[1]) || !p[1] || ISSPACE (p[-1])))
     3099        p = find_char_unquote (p+1, stopmap|MAP_VMSCOMMA|MAP_BLANK);
    29493100#endif
    29503101#ifdef HAVE_DOS_PATHS
     
    29533104       Note that tokens separated by spaces should be treated as separate
    29543105       tokens since make doesn't allow path names with spaces */
    2955     if (stopchar == ':')
    2956       while (p != 0 && !isspace ((unsigned char)*p) &&
     3106    if (stopmap | MAP_COLON)
     3107      while (p != 0 && !ISSPACE (*p) &&
    29573108             (p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1]))
    2958         p = find_char_unquote (p + 1, stopchar, VMS_COMMA, 1, 0);
     3109        p = find_char_unquote (p + 1, stopmap|MAP_VMSCOMMA|MAP_BLANK);
    29593110#endif
    29603111      if (p == 0)
    2961         p = s + strlen (s);
     3112        p = s + strlen (s);
    29623113
    29633114      /* Strip leading "this directory" references.  */
    2964       if (! (flags & PARSEFS_NOSTRIP))
     3115      if (NONE_SET (flags, PARSEFS_NOSTRIP))
    29653116#ifdef VMS
    2966         /* Skip leading `[]'s.  */
    2967         while (p - s > 2 && s[0] == '[' && s[1] == ']')
    2968 #else
    2969         /* Skip leading `./'s.  */
    2970         while (p - s > 2 && s[0] == '.' && s[1] == '/')
     3117        /* Skip leading '[]'s. should only be one set or bug somwhere else */
     3118        if (p - s > 2 && s[0] == '[' && s[1] == ']')
     3119            s += 2;
     3120        /* Skip leading '<>'s. should only be one set or bug somwhere else */
     3121        if (p - s > 2 && s[0] == '<' && s[1] == '>')
     3122            s += 2;
    29713123#endif
    2972           {
     3124        /* Skip leading './'s.  */
     3125        while (p - s > 2 && s[0] == '.' && s[1] == '/')
     3126          {
    29733127            /* Skip "./" and all following slashes.  */
    2974             s += 2;
    2975             while (*s == '/')
    2976               ++s;
    2977           }
     3128            s += 2;
     3129            while (*s == '/')
     3130              ++s;
     3131          }
    29783132
    29793133      /* Extract the filename just found, and skip it.
     
    29823136      if (s == p)
    29833137        {
    2984         /* The name was stripped to empty ("./"). */
    2985 #if defined(VMS)
    2986           continue;
    2987 #elif defined(_AMIGA)
     3138        /* The name was stripped to empty ("./"). */
     3139#if defined(_AMIGA)
    29883140          /* PDS-- This cannot be right!! */
    29893141          tp[0] = '\0';
     
    29973149        }
    29983150      else
    2999         {
     3151        {
    30003152#ifdef VMS
    30013153/* VMS filenames can have a ':' in them but they have to be '\'ed but we need
     
    30033155 * xstrdup called because S may be read-only string constant.
    30043156 */
    3005           char *n = tp;
    3006           while (s < p)
    3007             {
    3008               if (s[0] == '\\' && s[1] == ':')
     3157          char *n = tp;
     3158          while (s < p)
     3159            {
     3160              if (s[0] == '\\' && s[1] == ':')
    30093161                ++s;
    3010               *(n++) = *(s++);
    3011             }
     3162              *(n++) = *(s++);
     3163            }
    30123164          n[0] = '\0';
    30133165          nlen = strlen (tp);
     
    30283180
    30293181         TP == TMP means we're not already in an archive group.  Ignore
    3030          something starting with `(', as that cannot actually be an
     3182         something starting with '(', as that cannot actually be an
    30313183         archive-member reference (and treating it as such results in an empty
    30323184         file name, which causes much lossage).  Also if it ends in ")" then
     
    30363188         character, so ensure there's some word ending like that before
    30373189         considering this an archive group.  */
    3038       if (! (flags & PARSEFS_NOAR)
     3190      if (NONE_SET (flags, PARSEFS_NOAR)
    30393191          && tp == tmpbuf && tp[0] != '(' && tp[nlen-1] != ')')
    30403192        {
     
    30443196              /* This looks like the first element in an open archive group.
    30453197                 A valid group MUST have ')' as the last character.  */
    3046               const char *e = p + nlen;
     3198              const char *e = p;
    30473199              do
    30483200                {
    3049                   e = next_token (e);
     3201                  const char *o = e;
     3202                  NEXT_TOKEN (e);
    30503203                  /* Find the end of this word.  We don't want to unquote and
    30513204                     we don't care about quoting since we're looking for the
    30523205                     last char in the word. */
    3053                   while (*e != '\0' && *e != stopchar && *e != VMS_COMMA
    3054                          && ! isblank ((unsigned char) *e))
     3206                  while (! STOP_SET (*e, stopmap|MAP_BLANK|MAP_VMSCOMMA))
    30553207                    ++e;
     3208                  /* If we didn't move, we're done now.  */
     3209                  if (e == o)
     3210                    break;
    30563211                  if (e[-1] == ')')
    30573212                    {
     
    30623217                      tp = n + 1;
    30633218
    3064                       /* If we have just "lib(", part of something like
    3065                          "lib( a b)", go to the next item.  */
    3066                       if (! nlen)
    3067                         continue;
    3068 
    30693219                      /* We can stop looking now.  */
    30703220                      break;
     
    30723222                }
    30733223              while (*e != '\0');
     3224
     3225              /* If we have just "lib(", part of something like "lib( a b)",
     3226                 go to the next item.  */
     3227              if (! nlen)
     3228                continue;
    30743229            }
    30753230        }
     
    30983253      /* If we're not globbing we're done: add it to the end of the chain.
    30993254         Go to the next item in the string.  */
    3100       if (flags & PARSEFS_NOGLOB)
    3101         {
    3102           NEWELT (concat (2, prefix, tp));
     3255      if (ANY_SET (flags, PARSEFS_NOGLOB))
     3256        {
     3257          NEWELT (concat (2, prefix, tmpbuf));
    31033258          continue;
    31043259        }
     
    31073262         TP is a string in tmpbuf.  NLEN is no longer used.
    31083263         We may need to do more work: after this NAME will be set.  */
    3109       name = tp;
     3264      name = tmpbuf;
    31103265
    31113266      /* Expand tilde if applicable.  */
    3112       if (tp[0] == '~')
    3113         {
    3114           tildep = tilde_expand (tp);
    3115           if (tildep != 0)
     3267      if (tmpbuf[0] == '~')
     3268        {
     3269          tildep = tilde_expand (tmpbuf);
     3270          if (tildep != 0)
    31163271            name = tildep;
    3117         }
     3272        }
    31183273
    31193274#ifndef NO_ARCHIVES
     
    31213276         file name, and save the member name in MEMNAME.  We will glob on the
    31223277         archive name and then reattach MEMNAME later.  */
    3123       if (! (flags & PARSEFS_NOAR) && ar_name (name))
    3124         {
    3125           ar_parse_name (name, &arname, &memname);
    3126           name = arname;
    3127         }
     3278      if (NONE_SET (flags, PARSEFS_NOAR) && ar_name (name))
     3279        {
     3280          ar_parse_name (name, &arname, &memname);
     3281          name = arname;
     3282        }
    31283283#endif /* !NO_ARCHIVES */
    31293284
    3130       switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
    3131         {
    3132         case GLOB_NOSPACE:
    3133           fatal (NILF, _("virtual memory exhausted"));
    3134 
    3135         case 0:
    3136           /* Success.  */
    3137           i = gl.gl_pathc;
    3138           nlist = (const char **)gl.gl_pathv;
    3139           break;
    3140 
    3141         case GLOB_NOMATCH:
    3142           /* If we want only existing items, skip this one.  */
    3143           if (flags & PARSEFS_EXISTS)
    3144             {
    3145               i = 0;
    3146               break;
    3147             }
    3148           /* FALLTHROUGH */
    3149 
    3150         default:
    3151           /* By default keep this name.  */
     3285      /* glob() is expensive: don't call it unless we need to.  */
     3286      if (NONE_SET (flags, PARSEFS_EXISTS) && strpbrk (name, "?*[") == NULL)
     3287        {
     3288          globme = 0;
    31523289          i = 1;
    31533290          nlist = &name;
    3154           break;
    3155         }
     3291        }
     3292      else
     3293        switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
     3294          {
     3295          case GLOB_NOSPACE:
     3296            OUT_OF_MEM();
     3297
     3298          case 0:
     3299            /* Success.  */
     3300            i = gl.gl_pathc;
     3301            nlist = (const char **)gl.gl_pathv;
     3302            break;
     3303
     3304          case GLOB_NOMATCH:
     3305            /* If we want only existing items, skip this one.  */
     3306            if (ANY_SET (flags, PARSEFS_EXISTS))
     3307              {
     3308                i = 0;
     3309                break;
     3310              }
     3311            /* FALLTHROUGH */
     3312
     3313          default:
     3314            /* By default keep this name.  */
     3315            i = 1;
     3316            nlist = &name;
     3317            break;
     3318          }
    31563319
    31573320      /* For each matched element, add it to the list.  */
     
    31683331              {
    31693332                /* We got a chain of items.  Attach them.  */
    3170                 (*newp)->next = found;
     3333                if (*newp)
     3334                  (*newp)->next = found;
     3335                else
     3336                  *newp = found;
    31713337
    31723338                /* Find and set the new end.  Massage names if necessary.  */
     
    31903356          NEWELT (concat (2, prefix, nlist[i]));
    31913357
    3192       globfree (&gl);
     3358      if (globme)
     3359        globfree (&gl);
    31933360
    31943361#ifndef NO_ARCHIVES
    3195       if (arname)
    3196         free (arname);
     3362      free (arname);
    31973363#endif
    31983364
    3199       if (tildep)
    3200         free (tildep);
     3365      free (tildep);
    32013366    }
    32023367
Note: See TracChangeset for help on using the changeset viewer.