/* Reading and parsing of makefiles for GNU Make.
-Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-2010 Free Software Foundation, Inc.
+Copyright (C) 1988-2013 Free Software Foundation, Inc.
This file is part of GNU Make.
GNU Make is free software; you can redistribute it and/or modify it under the
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "make.h"
+#include "makeint.h"
#include <assert.h>
#include <glob.h>
-#include "dep.h"
#include "filedef.h"
+#include "dep.h"
#include "job.h"
#include "commands.h"
#include "variable.h"
#include "hash.h"
-#ifndef WINDOWS32
+#ifdef WINDOWS32
+#include <windows.h>
+#include "sub_proc.h"
+#else /* !WINDOWS32 */
#ifndef _AMIGA
#ifndef VMS
#include <pwd.h>
char *bufstart; /* Start of the entire buffer. */
unsigned int size; /* Malloc'd size of buffer. */
FILE *fp; /* File, or NULL if this is an internal buffer. */
- struct floc floc; /* Info on the file in fp (if any). */
+ gmk_floc floc; /* Info on the file in fp (if any). */
};
/* Track the modifiers we can have on variable assignments */
};
-/* A `struct conditionals' contains the information describing
+/* A 'struct conditionals' contains the information describing
all the active conditionals in a makefile.
- The global variable `conditionals' contains the conditionals
+ The global variable 'conditionals' contains the conditionals
information for the current makefile. It is initialized from
- the static structure `toplevel_conditionals' and is later changed
+ the static structure 'toplevel_conditionals' and is later changed
to new structures for included makefiles. */
struct conditionals
{
- unsigned int if_cmds; /* Depth of conditional nesting. */
- unsigned int allocated; /* Elts allocated in following arrays. */
- char *ignoring; /* Are we ignoring or interpreting?
+ unsigned int if_cmds; /* Depth of conditional nesting. */
+ unsigned int allocated; /* Elts allocated in following arrays. */
+ char *ignoring; /* Are we ignoring or interpreting?
0=interpreting, 1=not yet interpreted,
2=already interpreted */
- char *seen_else; /* Have we already seen an `else'? */
+ char *seen_else; /* Have we already seen an 'else'? */
};
static struct conditionals toplevel_conditionals;
/* The filename and pointer to line number of the
makefile currently being read in. */
-const struct floc *reading_file = 0;
+const gmk_floc *reading_file = 0;
-/* The chain of makefiles read by read_makefile. */
+/* The chain of files read by read_all_makefiles. */
-static struct dep *read_makefiles = 0;
+static struct dep *read_files = 0;
static int eval_makefile (const char *filename, int flags);
static void eval (struct ebuffer *buffer, int flags);
struct ebuffer *ebuf);
static struct variable *do_define (char *name, enum variable_origin origin,
struct ebuffer *ebuf);
-static int conditional_line (char *line, int len, const struct floc *flocp);
+static int conditional_line (char *line, int len, const gmk_floc *flocp);
static void record_files (struct nameseq *filenames, const char *pattern,
const char *pattern_percent, char *depstr,
unsigned int cmds_started, char *commands,
unsigned int commands_idx, int two_colon,
- const struct floc *flocp);
+ char prefix, const gmk_floc *flocp);
static void record_target_var (struct nameseq *filenames, char *defn,
enum variable_origin origin,
struct vmodifiers *vmod,
- const struct floc *flocp);
+ const gmk_floc *flocp);
static enum make_word_type get_next_mword (char *buffer, char *delim,
char **startp, unsigned int *length);
static void remove_comments (char *line);
-static char *find_char_unquote (char *string, int stop1, int stop2,
- int blank, int ignorevars);
+static char *find_char_unquote (char *string, int map);
+static char *unescape_char (char *string, int c);
/* Compare a word, both length and contents.
P must point to the word to be tested, and WLEN must be the length.
*/
-#define word1eq(s) (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))
+#define word1eq(s) (wlen == CSTRLEN (s) && strneq (s, p, CSTRLEN (s)))
\f
-/* Read in all the makefiles and return the chain of their names. */
+/* Read in all the makefiles and return a chain of targets to rebuild. */
struct dep *
read_all_makefiles (const char **makefiles)
while ((name = find_next_token ((const char **)&p, &length)) != 0)
{
- if (*p != '\0')
- *p++ = '\0';
- eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
+ if (*p != '\0')
+ *p++ = '\0';
+ eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE);
}
free (value);
if (makefiles != 0)
while (*makefiles != 0)
{
- struct dep *tail = read_makefiles;
- register struct dep *d;
+ struct dep *tail = read_files;
+ struct dep *d;
- if (! eval_makefile (*makefiles, 0))
- perror_with_name ("", *makefiles);
+ if (! eval_makefile (*makefiles, 0))
+ perror_with_name ("", *makefiles);
- /* Find the right element of read_makefiles. */
- d = read_makefiles;
- while (d->next != tail)
- d = d->next;
+ /* Find the first element eval_makefile() added to read_files. */
+ d = read_files;
+ while (d->next != tail)
+ d = d->next;
- /* Use the storage read_makefile allocates. */
- *makefiles = dep_name (d);
- ++num_makefiles;
- ++makefiles;
+ /* Reuse the storage allocated for the read_file. */
+ *makefiles = dep_name (d);
+ ++num_makefiles;
+ ++makefiles;
}
/* If there were no -f switches, try the default names. */
{
static char *default_makefiles[] =
#ifdef VMS
- /* all lower case since readdir() (the vms version) 'lowercasifies' */
- { "makefile.vms", "gnumakefile.", "makefile.", 0 };
+ /* all lower case since readdir() (the vms version) 'lowercasifies' */
+ { "makefile.vms", "gnumakefile.", "makefile.", 0 };
#else
#ifdef _AMIGA
- { "GNUmakefile", "Makefile", "SMakefile", 0 };
+ { "GNUmakefile", "Makefile", "SMakefile", 0 };
#else /* !Amiga && !VMS */
- { "GNUmakefile", "makefile", "Makefile", 0 };
+ { "GNUmakefile", "makefile", "Makefile", 0 };
#endif /* AMIGA */
#endif /* VMS */
register char **p = default_makefiles;
while (*p != 0 && !file_exists_p (*p))
- ++p;
+ ++p;
if (*p != 0)
- {
- if (! eval_makefile (*p, 0))
- perror_with_name ("", *p);
- }
+ {
+ if (! eval_makefile (*p, 0))
+ perror_with_name ("", *p);
+ }
else
- {
- /* No default makefile was found. Add the default makefiles to the
- `read_makefiles' chain so they will be updated if possible. */
- struct dep *tail = read_makefiles;
- /* Add them to the tail, after any MAKEFILES variable makefiles. */
- while (tail != 0 && tail->next != 0)
- tail = tail->next;
- for (p = default_makefiles; *p != 0; ++p)
- {
- struct dep *d = alloc_dep ();
- d->file = enter_file (strcache_add (*p));
- d->dontcare = 1;
- /* Tell update_goal_chain to bail out as soon as this file is
- made, and main not to die if we can't make this file. */
- d->changed = RM_DONTCARE;
- if (tail == 0)
- read_makefiles = d;
- else
- tail->next = d;
- tail = d;
- }
- if (tail != 0)
- tail->next = 0;
- }
+ {
+ /* No default makefile was found. Add the default makefiles to the
+ 'read_files' chain so they will be updated if possible. */
+ struct dep *tail = read_files;
+ /* Add them to the tail, after any MAKEFILES variable makefiles. */
+ while (tail != 0 && tail->next != 0)
+ tail = tail->next;
+ for (p = default_makefiles; *p != 0; ++p)
+ {
+ struct dep *d = alloc_dep ();
+ d->file = enter_file (strcache_add (*p));
+ d->dontcare = 1;
+ /* Tell update_goal_chain to bail out as soon as this file is
+ made, and main not to die if we can't make this file. */
+ d->changed = RM_DONTCARE;
+ if (tail == 0)
+ read_files = d;
+ else
+ tail->next = d;
+ tail = d;
+ }
+ if (tail != 0)
+ tail->next = 0;
+ }
}
- return read_makefiles;
+ return read_files;
}
\f
/* Install a new conditional and return the previous one. */
{
struct dep *deps;
struct ebuffer ebuf;
- const struct floc *curfile;
+ const gmk_floc *curfile;
char *expanded = 0;
int makefile_errno;
- filename = strcache_add (filename);
- ebuf.floc.filenm = filename;
+ ebuf.floc.filenm = filename; /* Use the original file name. */
ebuf.floc.lineno = 1;
if (ISDB (DB_VERBOSE))
{
- printf (_("Reading makefile `%s'"), filename);
+ printf (_("Reading makefile '%s'"), filename);
if (flags & RM_NO_DEFAULT_GOAL)
- printf (_(" (no default goal)"));
+ printf (_(" (no default goal)"));
if (flags & RM_INCLUDED)
- printf (_(" (search path)"));
+ printf (_(" (search path)"));
if (flags & RM_DONTCARE)
- printf (_(" (don't care)"));
+ printf (_(" (don't care)"));
if (flags & RM_NO_TILDE)
- printf (_(" (no ~ expansion)"));
+ printf (_(" (no ~ expansion)"));
puts ("...");
}
/* First, get a stream to read. */
- /* Expand ~ in FILENAME unless it came from `include',
+ /* Expand ~ in FILENAME unless it came from 'include',
in which case it was already done. */
if (!(flags & RM_NO_TILDE) && filename[0] == '~')
{
expanded = tilde_expand (filename);
if (expanded != 0)
- filename = expanded;
+ filename = expanded;
}
- ebuf.fp = fopen (filename, "r");
+ ENULLLOOP (ebuf.fp, fopen (filename, "r"));
+
/* Save the error code so we print the right message later. */
makefile_errno = errno;
+ /* Check for unrecoverable errors: out of mem or FILE slots. */
+ switch (makefile_errno)
+ {
+#ifdef EMFILE
+ case EMFILE:
+#endif
+#ifdef ENFILE
+ case ENFILE:
+#endif
+ case ENOMEM:
+ fatal (reading_file, "%s", strerror (makefile_errno));
+ }
+
/* If the makefile wasn't found and it's either a makefile from
- the `MAKEFILES' variable or an included makefile,
+ the 'MAKEFILES' variable or an included makefile,
search the included makefile search path for this makefile. */
if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/')
{
unsigned int i;
for (i = 0; include_directories[i] != 0; ++i)
- {
- const char *included = concat (3, include_directories[i],
+ {
+ const char *included = concat (3, include_directories[i],
"/", filename);
- ebuf.fp = fopen (included, "r");
- if (ebuf.fp)
- {
- filename = strcache_add (included);
- break;
- }
- }
+ ebuf.fp = fopen (included, "r");
+ if (ebuf.fp)
+ {
+ filename = included;
+ break;
+ }
+ }
}
+ /* Now we have the final name for this makefile. Enter it into
+ the cache. */
+ filename = strcache_add (filename);
+
/* Add FILENAME to the chain of read makefiles. */
deps = alloc_dep ();
- deps->next = read_makefiles;
- read_makefiles = deps;
+ deps->next = read_files;
+ read_files = deps;
deps->file = lookup_file (filename);
if (deps->file == 0)
deps->file = enter_file (filename);
if (ebuf.fp == 0)
{
/* If we did some searching, errno has the error from the last
- attempt, rather from FILENAME itself. Restore it in case the
- caller wants to use it in a message. */
+ attempt, rather from FILENAME itself. Restore it in case the
+ caller wants to use it in a message. */
errno = makefile_errno;
return 0;
}
}
void
-eval_buffer (char *buffer)
+eval_buffer (char *buffer, const gmk_floc *floc)
{
struct ebuffer ebuf;
struct conditionals *saved;
struct conditionals new;
- const struct floc *curfile;
+ const gmk_floc *curfile;
/* Evaluate the buffer */
ebuf.buffer = ebuf.bufnext = ebuf.bufstart = buffer;
ebuf.fp = NULL;
- if (reading_file)
+ if (floc)
+ ebuf.floc = *floc;
+ else if (reading_file)
ebuf.floc = *reading_file;
else
- ebuf.floc.filenm = NULL;
+ {
+ ebuf.floc.filenm = NULL;
+ ebuf.floc.lineno = 1;
+ }
curfile = reading_file;
reading_file = &ebuf.floc;
{
int wlen;
const char *p2;
- enum variable_flavor flavor;
+ struct variable v;
- p2 = parse_variable_definition (p, &flavor);
+ p2 = parse_variable_definition (p, &v);
/* If this is a variable assignment, we're done. */
if (p2)
unsigned int commands_idx = 0;
unsigned int cmds_started, tgts_started;
int ignoring = 0, in_ignored_define = 0;
- int no_targets = 0; /* Set when reading a rule without targets. */
+ int no_targets = 0; /* Set when reading a rule without targets. */
struct nameseq *filenames = 0;
char *depstr = 0;
long nlines = 0;
int two_colon = 0;
+ char prefix = cmd_prefix;
const char *pattern = 0;
const char *pattern_percent;
- struct floc *fstart;
- struct floc fi;
+ gmk_floc *fstart;
+ gmk_floc fi;
-#define record_waiting_files() \
- do \
- { \
- if (filenames != 0) \
+#define record_waiting_files() \
+ do \
+ { \
+ if (filenames != 0) \
{ \
- fi.lineno = tgts_started; \
- record_files (filenames, pattern, pattern_percent, depstr, \
+ fi.lineno = tgts_started; \
+ record_files (filenames, pattern, pattern_percent, depstr, \
cmds_started, commands, commands_idx, two_colon, \
- &fi); \
- filenames = 0; \
+ prefix, &fi); \
+ filenames = 0; \
} \
- commands_idx = 0; \
+ commands_idx = 0; \
no_targets = 0; \
pattern = 0; \
} while (0)
when the start of the next rule (or eof) is encountered.
When you see a "continue" in the loop below, that means we are moving on
- to the next line _without_ ending any rule that we happen to be working
- with at the moment. If you see a "goto rule_complete", then the
- statement we just parsed also finishes the previous rule. */
+ to the next line. If you see record_waiting_files(), then the statement
+ we are parsing also finishes the previous rule. */
commands = xmalloc (200);
if (nlines < 0)
break;
- /* If this line is empty, skip it. */
line = ebuf->buffer;
+
+ /* If this is the first line, check for a UTF-8 BOM and skip it. */
+ if (ebuf->floc.lineno == 1 && line[0] == (char)0xEF
+ && line[1] == (char)0xBB && line[2] == (char)0xBF)
+ {
+ line += 3;
+ if (ISDB(DB_BASIC))
+ {
+ if (ebuf->floc.filenm)
+ printf (_("Skipping UTF-8 BOM in makefile '%s'\n"),
+ ebuf->floc.filenm);
+ else
+ printf (_("Skipping UTF-8 BOM in makefile buffer\n"));
+ }
+ }
+
+ /* If this line is empty, skip it. */
if (line[0] == '\0')
continue;
linelen = strlen (line);
/* Check for a shell command line first.
- If it is not one, we can stop treating tab specially. */
+ If it is not one, we can stop treating cmd_prefix specially. */
if (line[0] == cmd_prefix)
- {
- if (no_targets)
- /* Ignore the commands in a rule with no targets. */
- continue;
-
- /* If there is no preceding rule line, don't treat this line
- as a command, even though it begins with a recipe prefix.
- SunOS 4 make appears to behave this way. */
-
- if (filenames != 0)
- {
- if (ignoring)
- /* Yep, this is a shell command, and we don't care. */
- continue;
-
- /* Append this command line to the line being accumulated.
- Strip command prefix chars that appear after newlines. */
- if (commands_idx == 0)
- cmds_started = ebuf->floc.lineno;
-
- if (linelen + commands_idx > commands_len)
- {
- commands_len = (linelen + commands_idx) * 2;
- commands = xrealloc (commands, commands_len);
- }
- p = &commands[commands_idx];
- p2 = line + 1;
- while (--linelen)
+ {
+ if (no_targets)
+ /* Ignore the commands in a rule with no targets. */
+ continue;
+
+ /* If there is no preceding rule line, don't treat this line
+ as a command, even though it begins with a recipe prefix.
+ SunOS 4 make appears to behave this way. */
+
+ if (filenames != 0)
+ {
+ if (ignoring)
+ /* Yep, this is a shell command, and we don't care. */
+ continue;
+
+ if (commands_idx == 0)
+ cmds_started = ebuf->floc.lineno;
+
+ /* Append this command line to the line being accumulated.
+ Skip the initial command prefix character. */
+ if (linelen + commands_idx > commands_len)
{
- ++commands_idx;
- *(p++) = *p2;
- if (p2[0] == '\n' && p2[1] == cmd_prefix)
- {
- ++p2;
- --linelen;
- }
- ++p2;
+ commands_len = (linelen + commands_idx) * 2;
+ commands = xrealloc (commands, commands_len);
}
- *p = '\n';
- ++commands_idx;
-
- continue;
- }
- }
+ memcpy (&commands[commands_idx], line + 1, linelen - 1);
+ commands_idx += linelen - 1;
+ commands[commands_idx++] = '\n';
+ continue;
+ }
+ }
/* This line is not a shell command line. Don't worry about whitespace.
Get more space if we need it; we don't need to preserve the current
contents of the buffer. */
if (collapsed_length < linelen+1)
- {
- collapsed_length = linelen+1;
+ {
+ collapsed_length = linelen+1;
if (collapsed)
free (collapsed);
/* Don't need xrealloc: we don't need to preserve the content. */
- collapsed = xmalloc (collapsed_length);
- }
+ collapsed = xmalloc (collapsed_length);
+ }
strcpy (collapsed, line);
/* Collapse continuation lines. */
collapse_continuations (collapsed);
/* See if this is a variable assignment. We need to do this early, to
allow variables with names like 'ifdef', 'export', 'private', etc. */
- p = parse_var_assignment(p, &vmod);
+ p = parse_var_assignment (p, &vmod);
if (vmod.assign_v)
{
struct variable *v;
enum variable_origin origin = vmod.override_v ? o_override : o_file;
+ /* Variable assignment ends the previous rule. */
+ record_waiting_files ();
+
/* If we're ignoring then we're done now. */
- if (ignoring)
+ if (ignoring)
{
if (vmod.define_v)
in_ignored_define = 1;
if (vmod.undefine_v)
{
do_undefine (p, origin, ebuf);
-
- /* This line has been dealt with. */
- goto rule_complete;
+ continue;
}
else if (vmod.define_v)
v = do_define (p, origin, ebuf);
v->private_var = 1;
/* This line has been dealt with. */
- goto rule_complete;
+ continue;
}
/* If this line is completely empty, ignore it. */
if (*p == '\0')
- continue;
+ continue;
p2 = end_of_token (p);
wlen = p2 - p;
/* If we're in an ignored define, skip this line (but maybe get out). */
if (in_ignored_define)
- {
+ {
/* See if this is an endef line (plus optional comment). */
- if (word1eq ("endef") && (*p2 == '\0' || *p2 == '#'))
+ if (word1eq ("endef") && STOP_SET (*p2, MAP_COMMENT|MAP_NUL))
in_ignored_define = 0;
- continue;
- }
+ continue;
+ }
/* Check for conditional state changes. */
{
/* Nothing to see here... move along. */
if (ignoring)
- continue;
+ continue;
/* Manage the "export" keyword used outside of variable assignment
as well as "unexport". */
if (word1eq ("export") || word1eq ("unexport"))
- {
+ {
int exporting = *p == 'u' ? 0 : 1;
+ /* Export/unexport ends the previous rule. */
+ record_waiting_files ();
+
/* (un)export by itself causes everything to be (un)exported. */
- if (*p2 == '\0')
+ if (*p2 == '\0')
export_all_variables = exporting;
else
{
{
struct variable *v = lookup_variable (p, l);
if (v == 0)
- v = define_variable_loc (p, l, "", o_file, 0, fstart);
+ v = define_variable_global (p, l, "", o_file, 0, fstart);
v->export = exporting ? v_export : v_noexport;
}
free (ap);
}
- goto rule_complete;
- }
+ continue;
+ }
/* Handle the special syntax for vpath. */
if (word1eq ("vpath"))
- {
+ {
const char *cp;
- char *vpat;
- unsigned int l;
- cp = variable_expand (p2);
- p = find_next_token (&cp, &l);
- if (p != 0)
- {
- vpat = xstrndup (p, l);
- p = find_next_token (&cp, &l);
- /* No searchpath means remove all previous
- selective VPATH's with the same pattern. */
- }
- else
- /* No pattern means remove all previous selective VPATH's. */
- vpat = 0;
- construct_vpath_list (vpat, p);
- if (vpat != 0)
- free (vpat);
-
- goto rule_complete;
- }
+ char *vpat;
+ unsigned int l;
+
+ /* vpath ends the previous rule. */
+ record_waiting_files ();
+
+ cp = variable_expand (p2);
+ p = find_next_token (&cp, &l);
+ if (p != 0)
+ {
+ vpat = xstrndup (p, l);
+ p = find_next_token (&cp, &l);
+ /* No searchpath means remove all previous
+ selective VPATH's with the same pattern. */
+ }
+ else
+ /* No pattern means remove all previous selective VPATH's. */
+ vpat = 0;
+ construct_vpath_list (vpat, p);
+ if (vpat != 0)
+ free (vpat);
+
+ continue;
+ }
/* Handle include and variants. */
if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude"))
- {
- /* We have found an `include' line specifying a nested
- makefile to be read at this point. */
- struct conditionals *save;
+ {
+ /* We have found an 'include' line specifying a nested
+ makefile to be read at this point. */
+ struct conditionals *save;
struct conditionals new_conditionals;
- struct nameseq *files;
- /* "-include" (vs "include") says no error if the file does not
- exist. "sinclude" is an alias for this from SGI. */
- int noerror = (p[0] != 'i');
+ struct nameseq *files;
+ /* "-include" (vs "include") says no error if the file does not
+ exist. "sinclude" is an alias for this from SGI. */
+ int noerror = (p[0] != 'i');
- p = allocated_variable_expand (p2);
+ /* Include ends the previous rule. */
+ record_waiting_files ();
+
+ p = allocated_variable_expand (p2);
/* If no filenames, it's a no-op. */
- if (*p == '\0')
+ if (*p == '\0')
{
free (p);
continue;
}
- /* Parse the list of file names. Don't expand archive references! */
- p2 = p;
- files = PARSE_FILE_SEQ (&p2, struct nameseq, '\0', NULL,
+ /* Parse the list of file names. Don't expand archive references! */
+ p2 = p;
+ files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL,
PARSEFS_NOAR);
- free (p);
+ free (p);
- /* Save the state of conditionals and start
- the included makefile with a clean slate. */
- save = install_conditionals (&new_conditionals);
+ /* Save the state of conditionals and start
+ the included makefile with a clean slate. */
+ save = install_conditionals (&new_conditionals);
- /* Record the rules that are waiting so they will determine
- the default goal before those in the included makefile. */
- record_waiting_files ();
+ /* Record the rules that are waiting so they will determine
+ the default goal before those in the included makefile. */
+ record_waiting_files ();
- /* Read each included makefile. */
- while (files != 0)
- {
- struct nameseq *next = files->next;
- const char *name = files->name;
+ /* Read each included makefile. */
+ while (files != 0)
+ {
+ struct nameseq *next = files->next;
+ const char *name = files->name;
int r;
- free_ns (files);
- files = next;
+ free_ns (files);
+ files = next;
r = eval_makefile (name,
(RM_INCLUDED | RM_NO_TILDE
| (noerror ? RM_DONTCARE : 0)
| (set_default ? 0 : RM_NO_DEFAULT_GOAL)));
- if (!r && !noerror)
+ if (!r && !noerror)
error (fstart, "%s: %s", name, strerror (errno));
- }
+ }
+
+ /* Restore conditional state. */
+ restore_conditionals (save);
+
+ continue;
+ }
+
+ /* Handle the load operations. */
+ if (word1eq ("load") || word1eq ("-load"))
+ {
+ /* A 'load' line specifies a dynamic object to load. */
+ struct nameseq *files;
+ int noerror = (p[0] == '-');
+
+ /* Load ends the previous rule. */
+ record_waiting_files ();
+
+ p = allocated_variable_expand (p2);
+
+ /* If no filenames, it's a no-op. */
+ if (*p == '\0')
+ {
+ free (p);
+ continue;
+ }
+
+ /* Parse the list of file names.
+ Don't expand archive references or strip "./" */
+ p2 = p;
+ files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL,
+ PARSEFS_NOAR);
+ free (p);
+
+ /* Load each file. */
+ while (files != 0)
+ {
+ struct nameseq *next = files->next;
+ const char *name = files->name;
+ struct dep *deps;
+ int r;
- /* Restore conditional state. */
- restore_conditionals (save);
+ /* Load the file. 0 means failure. */
+ r = load_file (&ebuf->floc, &name, noerror);
+ if (! r && ! noerror)
+ fatal (&ebuf->floc, _("%s: failed to load"), name);
- goto rule_complete;
- }
+ free_ns (files);
+ files = next;
+
+ /* Return of -1 means a special load: don't rebuild it. */
+ if (r == -1)
+ continue;
+
+ /* It succeeded, so add it to the list "to be rebuilt". */
+ deps = alloc_dep ();
+ deps->next = read_files;
+ read_files = deps;
+ deps->file = lookup_file (name);
+ if (deps->file == 0)
+ deps->file = enter_file (name);
+ deps->file->loaded = 1;
+ }
+
+ continue;
+ }
/* This line starts with a tab but was not caught above because there
was no preceding target, and the line might have been usable as a
variable definition. But now we know it is definitely lossage. */
if (line[0] == cmd_prefix)
- fatal(fstart, _("recipe commences before first target"));
+ fatal (fstart, _("recipe commences before first target"));
/* This line describes some target files. This is complicated by
the existence of target-specific variables, because we can't
expand the entire line until we know if we have one or not. So
- we expand the line word by word until we find the first `:',
+ we expand the line word by word until we find the first ':',
then check to see if it's a target-specific variable.
- In this algorithm, `lb_next' will point to the beginning of the
- unexpanded parts of the input buffer, while `p2' points to the
+ In this algorithm, 'lb_next' will point to the beginning of the
+ unexpanded parts of the input buffer, while 'p2' points to the
parts of the expanded buffer we haven't searched yet. */
{
/* Search the line for an unquoted ; that is not after an
unquoted #. */
- cmdleft = find_char_unquote (line, ';', '#', 0, 1);
+ cmdleft = find_char_unquote (line, MAP_SEMI|MAP_COMMENT|MAP_VARIABLE);
if (cmdleft != 0 && *cmdleft == '#')
{
/* We found a comment before a semicolon. */
variable we don't want to expand it. So, walk from the
beginning, expanding as we go, and looking for "interesting"
chars. The first word is always expandable. */
- wtype = get_next_mword(line, NULL, &lb_next, &wlen);
+ wtype = get_next_mword (line, NULL, &lb_next, &wlen);
switch (wtype)
{
case w_eol:
if (cmdleft != 0)
- fatal(fstart, _("missing rule before recipe"));
+ fatal (fstart, _("missing rule before recipe"));
/* This line contained something but turned out to be nothing
but whitespace (a comment?). */
continue;
break;
}
- p2 = variable_expand_string(NULL, lb_next, wlen);
+ p2 = variable_expand_string (NULL, lb_next, wlen);
while (1)
{
if (cmdleft == 0)
{
/* Look for a semicolon in the expanded line. */
- cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
+ cmdleft = find_char_unquote (p2, MAP_SEMI);
if (cmdleft != 0)
{
unsigned long p2_off = p2 - variable_buffer;
unsigned long cmd_off = cmdleft - variable_buffer;
- char *pend = p2 + strlen(p2);
+ char *pend = p2 + strlen (p2);
/* Append any remnants of lb, then cut the line short
at the semicolon. */
here, but merely copy, since now you're beyond a ";"
and into a command script. However, the old parser
expanded the whole line, so we continue that for
- backwards-compatiblity. Also, it wouldn't be
+ backwards-compatibility. Also, it wouldn't be
entirely consistent, since we do an unconditional
expand below once we know we don't have a
target-specific variable. */
- (void)variable_expand_string(pend, lb_next, (long)-1);
- lb_next += strlen(lb_next);
+ (void)variable_expand_string (pend, lb_next, (long)-1);
+ lb_next += strlen (lb_next);
p2 = variable_buffer + p2_off;
cmdleft = variable_buffer + cmd_off + 1;
}
}
- colonp = find_char_unquote(p2, ':', 0, 0, 0);
+ colonp = find_char_unquote (p2, MAP_COLON);
#ifdef HAVE_DOS_PATHS
/* The drive spec brain-damage strikes again... */
/* Note that the only separators of targets in this context
while (colonp && (colonp[1] == '/' || colonp[1] == '\\') &&
colonp > p2 && isalpha ((unsigned char)colonp[-1]) &&
(colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0))
- colonp = find_char_unquote(colonp + 1, ':', 0, 0, 0);
+ colonp = find_char_unquote (colonp + 1, MAP_COLON);
#endif
if (colonp != 0)
break;
- wtype = get_next_mword(lb_next, NULL, &lb_next, &wlen);
+ wtype = get_next_mword (lb_next, NULL, &lb_next, &wlen);
if (wtype == w_eol)
break;
- p2 += strlen(p2);
+ p2 += strlen (p2);
*(p2++) = ' ';
- p2 = variable_expand_string(p2, lb_next, wlen);
+ p2 = variable_expand_string (p2, lb_next, wlen);
/* We don't need to worry about cmdleft here, because if it was
found in the variable_buffer the entire buffer has already
been expanded... we'll never get here. */
/* There's no need to be ivory-tower about this: check for
one of the most common bugs found in makefiles... */
fatal (fstart, _("missing separator%s"),
- (cmd_prefix == '\t' && !strneq(line, " ", 8))
+ (cmd_prefix == '\t' && !strneq (line, " ", 8))
? "" : _(" (did you mean TAB instead of 8 spaces?)"));
continue;
}
/* Make the colon the end-of-string so we know where to stop
- looking for targets. */
+ looking for targets. Start there again once we're done. */
*colonp = '\0';
- filenames = PARSE_FILE_SEQ (&p2, struct nameseq, '\0', NULL, 0);
- *p2 = ':';
+ filenames = PARSE_SIMPLE_SEQ (&p2, struct nameseq);
+ *colonp = ':';
+ p2 = colonp;
if (!filenames)
{
after it. */
if (semip)
{
- unsigned int l = p - variable_buffer;
+ unsigned int l = p2 - variable_buffer;
*(--semip) = ';';
collapse_continuations (semip);
variable_buffer_output (p2 + strlen (p2),
semip, strlen (semip)+1);
- p = variable_buffer + l;
+ p2 = variable_buffer + l;
}
record_target_var (filenames, p2,
vmod.override_v ? o_override : o_file,
/* This is a normal target, _not_ a target-specific variable.
Unquote any = in the dependency list. */
- find_char_unquote (lb_next, '=', 0, 0, 0);
+ find_char_unquote (lb_next, MAP_EQUALS);
+
+ /* Remember the command prefix for this target. */
+ prefix = cmd_prefix;
/* We have some targets, so don't ignore the following commands. */
no_targets = 0;
/* Look for a semicolon in the expanded line. */
if (cmdleft == 0)
{
- cmdleft = find_char_unquote (p2, ';', 0, 0, 0);
+ cmdleft = find_char_unquote (p2, MAP_SEMI);
if (cmdleft != 0)
*(cmdleft++) = '\0';
}
}
- /* Is this a static pattern rule: `target: %targ: %dep; ...'? */
+ /* Is this a static pattern rule: 'target: %targ: %dep; ...'? */
p = strchr (p2, ':');
while (p != 0 && p[-1] == '\\')
{
if (p != 0)
{
struct nameseq *target;
- target = PARSE_FILE_SEQ (&p2, struct nameseq, ':', NULL,
+ target = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_COLON, NULL,
PARSEFS_NOGLOB);
++p2;
if (target == 0)
pattern_percent = find_percent_cached (&target->name);
pattern = target->name;
if (pattern_percent == 0)
- fatal (fstart, _("target pattern contains no `%%'"));
+ fatal (fstart, _("target pattern contains no '%%'"));
free_ns (target);
}
else
if (set_default && default_goal_var->value[0] == '\0')
{
- const char *name;
struct dep *d;
struct nameseq *t = filenames;
for (; t != 0; t = t->next)
{
int reject = 0;
- name = t->name;
+ const char *name = t->name;
/* We have nothing to do if this is an implicit rule. */
if (strchr (name, '%') != 0)
break;
- /* See if this target's name does not start with a `.',
+ /* See if this target's name does not start with a '.',
unless it contains a slash. */
if (*name == '.' && strchr (name, '/') == 0
#ifdef HAVE_DOS_PATHS
}
/* We get here except in the case that we just read a rule line.
- Record now the last rule we read, so following spurious
- commands are properly diagnosed. */
- rule_complete:
+ Record now the last rule we read, so following spurious
+ commands are properly diagnosed. */
record_waiting_files ();
}
-#undef word1eq
+#undef word1eq
if (conditionals->if_cmds)
- fatal (fstart, _("missing `endif'"));
+ fatal (fstart, _("missing 'endif'"));
/* At eof, record the last rule. */
record_waiting_files ();
{
char *comment;
- comment = find_char_unquote (line, '#', 0, 0, 0);
+ comment = find_char_unquote (line, MAP_COMMENT);
if (comment != 0)
/* Cut off the line at the #. */
*comment = '\0';
}
-/* Execute a `undefine' directive.
+/* Execute a 'undefine' directive.
The undefine line has already been read, and NAME is the name of
the variable to be undefined. */
free (var);
}
-/* Execute a `define' directive.
+/* Execute a 'define' directive.
The first line has already been read, and NAME is the name of
the variable to be defined. The following lines remain to be read. */
do_define (char *name, enum variable_origin origin, struct ebuffer *ebuf)
{
struct variable *v;
- enum variable_flavor flavor;
- struct floc defstart;
+ struct variable var;
+ gmk_floc defstart;
int nlevels = 1;
unsigned int length = 100;
char *definition = xmalloc (length);
unsigned int idx = 0;
- char *p, *var;
+ char *p, *n;
defstart = ebuf->floc;
- p = parse_variable_definition (name, &flavor);
+ p = parse_variable_definition (name, &var);
if (p == NULL)
/* No assignment token, so assume recursive. */
- flavor = f_recursive;
+ var.flavor = f_recursive;
else
{
- if (*(next_token (p)) != '\0')
- error (&defstart, _("extraneous text after `define' directive"));
+ if (var.value[0] != '\0')
+ error (&defstart, _("extraneous text after 'define' directive"));
/* Chop the string before the assignment token to get the name. */
- p[flavor == f_recursive ? -1 : -2] = '\0';
+ var.name[var.length] = '\0';
}
/* Expand the variable name and find the beginning (NAME) and end. */
- var = allocated_variable_expand (name);
- name = next_token (var);
- if (*name == '\0')
+ n = allocated_variable_expand (name);
+ name = next_token (n);
+ if (name[0] == '\0')
fatal (&defstart, _("empty variable name"));
p = name + strlen (name) - 1;
while (p > name && isblank ((unsigned char)*p))
/* If there is nothing left to be eval'd, there's no 'endef'!! */
if (nlines < 0)
- fatal (&defstart, _("missing `endef', unterminated `define'"));
+ fatal (&defstart, _("missing 'endef', unterminated 'define'"));
ebuf->floc.lineno += nlines;
line = ebuf->buffer;
remove_comments (p);
if (*(next_token (p)) != '\0')
error (&ebuf->floc,
- _("extraneous text after `endef' directive"));
+ _("extraneous text after 'endef' directive"));
if (--nlevels == 0)
break;
else
definition[idx - 1] = '\0';
- v = do_variable_definition (&defstart, name, definition, origin, flavor, 0);
+ v = do_variable_definition (&defstart, name,
+ definition, origin, var.flavor, 0);
free (definition);
- free (var);
+ free (n);
return (v);
}
\f
1 if following text should be ignored. */
static int
-conditional_line (char *line, int len, const struct floc *flocp)
+conditional_line (char *line, int len, const gmk_floc *flocp)
{
char *cmdname;
enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, c_else, c_endif } cmdtype;
unsigned int o;
/* Compare a word, both length and contents. */
-#define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))
-#define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
+#define word1eq(s) (len == CSTRLEN (s) && strneq (s, line, CSTRLEN (s)))
+#define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
/* Make sure this line is a conditional. */
chkword ("ifdef", c_ifdef)
/* Found one: skip past it and any whitespace after it. */
line = next_token (line + len);
-#define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname)
+#define EXTRANEOUS() error (flocp, _("extraneous text after '%s' directive"), cmdname)
/* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */
if (cmdtype == c_endif)
{
if (*line != '\0')
- EXTRANEOUS ();
+ EXTRANEOUS ();
if (!conditionals->if_cmds)
- fatal (flocp, _("extraneous `%s'"), cmdname);
+ fatal (flocp, _("extraneous '%s'"), cmdname);
--conditionals->if_cmds;
const char *p;
if (!conditionals->if_cmds)
- fatal (flocp, _("extraneous `%s'"), cmdname);
+ fatal (flocp, _("extraneous '%s'"), cmdname);
o = conditionals->if_cmds - 1;
if (conditionals->seen_else[o])
- fatal (flocp, _("only one `else' per conditional"));
+ fatal (flocp, _("only one 'else' per conditional"));
/* Change the state of ignorance. */
switch (conditionals->ignoring[o])
and cannot be an 'else' or 'endif'. */
/* Find the length of the next word. */
- for (p = line+1; *p != '\0' && !isspace ((unsigned char)*p); ++p)
+ for (p = line+1; ! STOP_SET (*p, MAP_SPACE|MAP_NUL); ++p)
;
len = p - line;
/* If it's 'else' or 'endif' or an illegal conditional, fail. */
- if (word1eq("else") || word1eq("endif")
+ if (word1eq ("else") || word1eq ("endif")
|| conditional_line (line, len, flocp) < 0)
- EXTRANEOUS ();
+ EXTRANEOUS ();
else
{
/* conditional_line() created a new level of conditional.
conditionals->allocated);
}
- /* Record that we have seen an `if...' but no `else' so far. */
+ /* Record that we have seen an 'if...' but no 'else' so far. */
conditionals->seen_else[o] = 0;
/* Search through the stack to see if we're already ignoring. */
for (i = 0; i < o; ++i)
if (conditionals->ignoring[i])
{
- /* We are already ignoring, so just push a level to match the next
- "else" or "endif", and keep ignoring. We don't want to expand
- variables in the condition. */
- conditionals->ignoring[o] = 1;
- return 1;
+ /* We are already ignoring, so just push a level to match the next
+ "else" or "endif", and keep ignoring. We don't want to expand
+ variables in the condition. */
+ conditionals->ignoring[o] = 1;
+ return 1;
}
if (cmdtype == c_ifdef || cmdtype == c_ifndef)
i = p - var;
p = next_token (p);
if (*p != '\0')
- return -1;
+ return -1;
var[i] = '\0';
v = lookup_variable (var, i);
char termin = *line == '(' ? ',' : *line;
if (termin != ',' && termin != '"' && termin != '\'')
- return -1;
+ return -1;
s1 = ++line;
/* Find the end of the first string. */
if (termin == ',')
- {
- int count = 0;
- for (; *line != '\0'; ++line)
- if (*line == '(')
- ++count;
- else if (*line == ')')
- --count;
- else if (*line == ',' && count <= 0)
- break;
- }
+ {
+ int count = 0;
+ for (; *line != '\0'; ++line)
+ if (*line == '(')
+ ++count;
+ else if (*line == ')')
+ --count;
+ else if (*line == ',' && count <= 0)
+ break;
+ }
else
- while (*line != '\0' && *line != termin)
- ++line;
+ while (*line != '\0' && *line != termin)
+ ++line;
if (*line == '\0')
- return -1;
+ return -1;
if (termin == ',')
- {
- /* Strip blanks after the first string. */
- char *p = line++;
- while (isblank ((unsigned char)p[-1]))
- --p;
- *p = '\0';
- }
+ {
+ /* Strip blanks after the first string. */
+ char *p = line++;
+ while (isblank ((unsigned char)p[-1]))
+ --p;
+ *p = '\0';
+ }
else
- *line++ = '\0';
+ *line++ = '\0';
s2 = variable_expand (s1);
/* We must allocate a new copy of the expanded string because
- variable_expand re-uses the same buffer. */
+ variable_expand re-uses the same buffer. */
l = strlen (s2);
s1 = alloca (l + 1);
memcpy (s1, s2, l + 1);
if (termin != ',')
- /* Find the start of the second string. */
- line = next_token (line);
+ /* Find the start of the second string. */
+ line = next_token (line);
termin = termin == ',' ? ')' : *line;
if (termin != ')' && termin != '"' && termin != '\'')
- return -1;
+ return -1;
/* Find the end of the second string. */
if (termin == ')')
- {
- int count = 0;
- s2 = next_token (line);
- for (line = s2; *line != '\0'; ++line)
- {
- if (*line == '(')
- ++count;
- else if (*line == ')')
- {
- if (count <= 0)
- break;
- else
- --count;
- }
- }
- }
+ {
+ int count = 0;
+ s2 = next_token (line);
+ for (line = s2; *line != '\0'; ++line)
+ {
+ if (*line == '(')
+ ++count;
+ else if (*line == ')')
+ {
+ if (count <= 0)
+ break;
+ else
+ --count;
+ }
+ }
+ }
else
- {
- ++line;
- s2 = line;
- while (*line != '\0' && *line != termin)
- ++line;
- }
+ {
+ ++line;
+ s2 = line;
+ while (*line != '\0' && *line != termin)
+ ++line;
+ }
if (*line == '\0')
- return -1;
+ return -1;
*line = '\0';
line = next_token (++line);
if (*line != '\0')
- EXTRANEOUS ();
+ EXTRANEOUS ();
s2 = variable_expand (s2);
conditionals->ignoring[o] = (streq (s1, s2) == (cmdtype == c_ifneq));
static void
record_target_var (struct nameseq *filenames, char *defn,
enum variable_origin origin, struct vmodifiers *vmod,
- const struct floc *flocp)
+ const gmk_floc *flocp)
{
struct nameseq *nextf;
struct variable_set_list *global;
{
struct variable *v;
const char *name = filenames->name;
- const char *fname;
const char *percent;
struct pattern_var *p;
v->value = allocated_variable_expand (v->value);
else
v->value = xstrdup (v->value);
-
- fname = p->target;
}
else
{
f = f->double_colon;
initialize_file_variables (f, 1);
- fname = f->name;
current_variable_set_list = f->variables;
v = try_variable_definition (flocp, defn, origin, 1);
if (v->origin != o_override)
{
struct variable *gv;
- int len = strlen(v->name);
+ int len = strlen (v->name);
gv = lookup_variable (v->name, len);
- if (gv && (gv->origin == o_env_override || gv->origin == o_command))
+ if (gv && v != gv
+ && (gv->origin == o_env_override || gv->origin == o_command))
{
if (v->value != 0)
free (v->value);
with dependencies DEPS, commands to execute described
by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED.
TWO_COLON is nonzero if a double colon was used.
- If not nil, PATTERN is the `%' pattern to make this
+ If not nil, PATTERN is the '%' pattern to make this
a static pattern rule, and PATTERN_PERCENT is a pointer
- to the `%' within it.
+ to the '%' within it.
The links of FILENAMES are freed, and so are any names in it
that are not incorporated into other data structures. */
const char *pattern_percent, char *depstr,
unsigned int cmds_started, char *commands,
unsigned int commands_idx, int two_colon,
- const struct floc *flocp)
+ char prefix, const gmk_floc *flocp)
{
struct commands *cmds;
struct dep *deps;
cmds->fileinfo.lineno = cmds_started;
cmds->commands = xstrndup (commands, commands_idx);
cmds->command_lines = 0;
+ cmds->recipe_prefix = prefix;
}
else
cmds = 0;
expansion: if so, snap_deps() will do it. */
if (depstr == 0)
deps = 0;
- else if (second_expansion && strchr (depstr, '$'))
- {
- deps = alloc_dep ();
- deps->name = depstr;
- deps->need_2nd_expansion = 1;
- deps->staticpattern = pattern != 0;
- }
else
{
- deps = split_prereqs (depstr);
- free (depstr);
-
- /* We'll enter static pattern prereqs later when we have the stem. We
- don't want to enter pattern rules at all so that we don't think that
- they ought to exist (make manual "Implicit Rule Search Algorithm",
- item 5c). */
- if (! pattern && ! implicit_percent)
- deps = enter_prereqs (deps, NULL);
+ depstr = unescape_char (depstr, ':');
+ if (second_expansion && strchr (depstr, '$'))
+ {
+ deps = alloc_dep ();
+ deps->name = depstr;
+ deps->need_2nd_expansion = 1;
+ deps->staticpattern = pattern != 0;
+ }
+ else
+ {
+ deps = split_prereqs (depstr);
+ free (depstr);
+
+ /* We'll enter static pattern prereqs later when we have the stem.
+ We don't want to enter pattern rules at all so that we don't
+ think that they ought to exist (make manual "Implicit Rule Search
+ Algorithm", item 5c). */
+ if (! pattern && ! implicit_percent)
+ deps = enter_prereqs (deps, NULL);
+ }
}
/* For implicit rules, _all_ the targets must have a pattern. That means we
if (implicit_percent == 0)
fatal (flocp, _("mixed implicit and normal rules"));
- targets[c] = name;
- target_pats[c] = implicit_percent;
+ targets[c] = name;
+ target_pats[c] = implicit_percent;
++c;
nextf = filenames->next;
{
posix_pedantic = 1;
define_variable_cname (".SHELLFLAGS", "-ec", o_default, 0);
+ /* These default values are based on IEEE Std 1003.1-2008. */
+ define_variable_cname ("ARFLAGS", "-rv", o_default, 0);
+ define_variable_cname ("CC", "c99", o_default, 0);
+ define_variable_cname ("CFLAGS", "-O", o_default, 0);
+ define_variable_cname ("FC", "fort77", o_default, 0);
+ define_variable_cname ("FFLAGS", "-O 1", o_default, 0);
+ define_variable_cname ("SCCSGETFLAGS", "-s", o_default, 0);
}
else if (streq (name, ".SECONDEXPANSION"))
second_expansion = 1;
-#if !defined(WINDOWS32) && !defined (__MSDOS__) && !defined (__EMX__)
+#if !defined (__MSDOS__) && !defined (__EMX__)
else if (streq (name, ".ONESHELL"))
one_shell = 1;
#endif
/* If this is a static pattern rule:
- `targets: target%pattern: prereq%pattern; recipe',
+ 'targets: target%pattern: prereq%pattern; recipe',
make sure the pattern matches this target name. */
if (pattern && !pattern_matches (pattern, pattern_percent, name))
- error (flocp, _("target `%s' doesn't match the target pattern"), name);
+ error (flocp, _("target '%s' doesn't match the target pattern"), name);
else if (deps)
/* If there are multiple targets, copy the chain DEPS for all but the
last one. It is not safe for the same deps to go in more than one
/* Find or create an entry in the file database for this target. */
if (!two_colon)
- {
- /* Single-colon. Combine this rule with the file's existing record,
- if any. */
- f = enter_file (strcache_add (name));
- if (f->double_colon)
- fatal (flocp,
- _("target file `%s' has both : and :: entries"), f->name);
-
- /* If CMDS == F->CMDS, this target was listed in this rule
- more than once. Just give a warning since this is harmless. */
- if (cmds != 0 && cmds == f->cmds)
- error (flocp,
- _("target `%s' given more than once in the same rule."),
+ {
+ /* Single-colon. Combine this rule with the file's existing record,
+ if any. */
+ f = enter_file (strcache_add (name));
+ if (f->double_colon)
+ fatal (flocp,
+ _("target file '%s' has both : and :: entries"), f->name);
+
+ /* If CMDS == F->CMDS, this target was listed in this rule
+ more than once. Just give a warning since this is harmless. */
+ if (cmds != 0 && cmds == f->cmds)
+ error (flocp,
+ _("target '%s' given more than once in the same rule"),
f->name);
- /* Check for two single-colon entries both with commands.
- Check is_target so that we don't lose on files such as .c.o
- whose commands were preinitialized. */
- else if (cmds != 0 && f->cmds != 0 && f->is_target)
- {
- error (&cmds->fileinfo,
- _("warning: overriding recipe for target `%s'"),
+ /* Check for two single-colon entries both with commands.
+ Check is_target so that we don't lose on files such as .c.o
+ whose commands were preinitialized. */
+ else if (cmds != 0 && f->cmds != 0 && f->is_target)
+ {
+ error (&cmds->fileinfo,
+ _("warning: overriding recipe for target '%s'"),
f->name);
- error (&f->cmds->fileinfo,
- _("warning: ignoring old recipe for target `%s'"),
+ error (&f->cmds->fileinfo,
+ _("warning: ignoring old recipe for target '%s'"),
f->name);
- }
-
- /* Defining .DEFAULT with no deps or cmds clears it. */
- if (f == default_file && this == 0 && cmds == 0)
- f->cmds = 0;
- if (cmds != 0)
- f->cmds = cmds;
-
- /* Defining .SUFFIXES with no dependencies clears out the list of
- suffixes. */
- if (f == suffix_file && this == 0)
- {
+ }
+
+ /* Defining .DEFAULT with no deps or cmds clears it. */
+ if (f == default_file && this == 0 && cmds == 0)
+ f->cmds = 0;
+ if (cmds != 0)
+ f->cmds = cmds;
+
+ /* Defining .SUFFIXES with no dependencies clears out the list of
+ suffixes. */
+ if (f == suffix_file && this == 0)
+ {
free_dep_chain (f->deps);
- f->deps = 0;
- }
- }
+ f->deps = 0;
+ }
+ }
else
- {
- /* Double-colon. Make a new record even if there already is one. */
- f = lookup_file (name);
-
- /* Check for both : and :: rules. Check is_target so we don't lose
- on default suffix rules or makefiles. */
- if (f != 0 && f->is_target && !f->double_colon)
- fatal (flocp,
- _("target file `%s' has both : and :: entries"), f->name);
-
- f = enter_file (strcache_add (name));
- /* If there was an existing entry and it was a double-colon entry,
- enter_file will have returned a new one, making it the prev
- pointer of the old one, and setting its double_colon pointer to
- the first one. */
- if (f->double_colon == 0)
- /* This is the first entry for this name, so we must set its
- double_colon pointer to itself. */
- f->double_colon = f;
-
- f->cmds = cmds;
- }
+ {
+ /* Double-colon. Make a new record even if there already is one. */
+ f = lookup_file (name);
+
+ /* Check for both : and :: rules. Check is_target so we don't lose
+ on default suffix rules or makefiles. */
+ if (f != 0 && f->is_target && !f->double_colon)
+ fatal (flocp,
+ _("target file '%s' has both : and :: entries"), f->name);
+
+ f = enter_file (strcache_add (name));
+ /* If there was an existing entry and it was a double-colon entry,
+ enter_file will have returned a new one, making it the prev
+ pointer of the old one, and setting its double_colon pointer to
+ the first one. */
+ if (f->double_colon == 0)
+ /* This is the first entry for this name, so we must set its
+ double_colon pointer to itself. */
+ f->double_colon = f;
+
+ f->cmds = cmds;
+ }
f->is_target = 1;
/* If this is a static pattern rule, set the stem to the part of its
- name that matched the `%' in the pattern, so you can use $* in the
+ name that matched the '%' in the pattern, so you can use $* in the
commands. If we didn't do it before, enter the prereqs now. */
if (pattern)
{
STOPCHAR _cannot_ be '$' if IGNOREVARS is true. */
static char *
-find_char_unquote (char *string, int stop1, int stop2, int blank,
- int ignorevars)
+find_char_unquote (char *string, int map)
{
unsigned int string_len = 0;
char *p = string;
- if (ignorevars)
- ignorevars = '$';
+ /* Always stop on NUL. */
+ map |= MAP_NUL;
while (1)
{
- if (stop2 && blank)
- while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2
- && ! isblank ((unsigned char) *p))
- ++p;
- else if (stop2)
- while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2)
- ++p;
- else if (blank)
- while (*p != '\0' && *p != ignorevars && *p != stop1
- && ! isblank ((unsigned char) *p))
- ++p;
- else
- while (*p != '\0' && *p != ignorevars && *p != stop1)
- ++p;
+ while (! STOP_SET (*p, map))
+ ++p;
if (*p == '\0')
- break;
+ break;
/* If we stopped due to a variable reference, skip over its contents. */
- if (*p == ignorevars)
+ if (STOP_SET (*p, MAP_VARIABLE))
{
char openparen = p[1];
}
if (p > string && p[-1] == '\\')
- {
- /* Search for more backslashes. */
- int i = -2;
- while (&p[i] >= string && p[i] == '\\')
- --i;
- ++i;
- /* Only compute the length if really needed. */
- if (string_len == 0)
- string_len = strlen (string);
- /* The number of backslashes is now -I.
- Copy P over itself to swallow half of them. */
- memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1);
- p += i/2;
- if (i % 2 == 0)
- /* All the backslashes quoted each other; the STOPCHAR was
- unquoted. */
- return p;
-
- /* The STOPCHAR was quoted by a backslash. Look for another. */
- }
+ {
+ /* Search for more backslashes. */
+ int i = -2;
+ while (&p[i] >= string && p[i] == '\\')
+ --i;
+ ++i;
+ /* Only compute the length if really needed. */
+ if (string_len == 0)
+ string_len = strlen (string);
+ /* The number of backslashes is now -I.
+ Copy P over itself to swallow half of them. */
+ memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1);
+ p += i/2;
+ if (i % 2 == 0)
+ /* All the backslashes quoted each other; the STOPCHAR was
+ unquoted. */
+ return p;
+
+ /* The STOPCHAR was quoted by a backslash. Look for another. */
+ }
else
- /* No backslash in sight. */
- return p;
+ /* No backslash in sight. */
+ return p;
}
/* Never hit a STOPCHAR or blank (with BLANK nonzero). */
return 0;
}
+/* Unescape a character in a string. The string is compressed onto itself. */
+
+static char *
+unescape_char (char *string, int c)
+{
+ char *p = string;
+ char *s = string;
+
+ while (*s != '\0')
+ {
+ if (*s == '\\')
+ {
+ char *e = s;
+ int l;
+
+ /* We found a backslash. See if it's escaping our character. */
+ while (*e == '\\')
+ ++e;
+ l = e - s;
+
+ if (*e != c || l%2 == 0)
+ {
+ /* It's not; just take it all without unescaping. */
+ memcpy (p, s, l);
+ p += l;
+ }
+ else if (l > 1)
+ {
+ /* It is, and there's >1 backslash. Take half of them. */
+ l /= 2;
+ memcpy (p, s, l);
+ p += l;
+ }
+ s = e;
+ }
+
+ *(p++) = *(s++);
+ }
+
+ *p = '\0';
+ return string;
+}
+
/* Search PATTERN for an unquoted % and handle quoting. */
char *
find_percent (char *pattern)
{
- return find_char_unquote (pattern, '%', 0, 0, 0);
+ return find_char_unquote (pattern, MAP_PERCENT);
}
/* Search STRING for an unquoted % and handle quoting. Returns a pointer to
while (1)
{
- while (*p != '\0' && *p != '%')
+ while (! STOP_SET (*p, MAP_PERCENT|MAP_NUL))
++p;
if (*p == '\0')
len = strlen (p);
if (len == 0)
- {
- /* This only happens when the first thing on the line is a '\0'.
- It is a pretty hopeless case, but (wonder of wonders) Athena
- lossage strikes again! (xmkmf puts NULs in its makefiles.)
- There is nothing really to be done; we synthesize a newline so
- the following line doesn't appear to be part of this line. */
- error (&ebuf->floc,
+ {
+ /* This only happens when the first thing on the line is a '\0'.
+ It is a pretty hopeless case, but (wonder of wonders) Athena
+ lossage strikes again! (xmkmf puts NULs in its makefiles.)
+ There is nothing really to be done; we synthesize a newline so
+ the following line doesn't appear to be part of this line. */
+ error (&ebuf->floc,
_("warning: NUL character seen; rest of line ignored"));
- p[0] = '\n';
- len = 1;
- }
+ p[0] = '\n';
+ len = 1;
+ }
/* Jump past the text we just read. */
p += len;
if ((p - start) > 1 && p[-2] == '\r')
{
--p;
- p[-1] = '\n';
+ memmove (p-1, p, strlen (p) + 1);
}
#endif
backslash = 0;
for (p2 = p - 2; p2 >= start; --p2)
- {
- if (*p2 != '\\')
- break;
+ {
+ if (*p2 != '\\')
+ break;
backslash = !backslash;
- }
+ }
if (!backslash)
- {
- p[-1] = '\0';
- break;
- }
+ {
+ p[-1] = '\0';
+ break;
+ }
/* It was a backslash/newline combo. If we have more space, read
another line. */
w_colon A colon
w_dcolon A double-colon
w_semicolon A semicolon
- w_varassign A variable assignment operator (=, :=, +=, or ?=)
+ w_varassign A variable assignment operator (=, :=, ::=, +=, ?=, or !=)
Note that this function is only used when reading certain parts of the
makefile. Don't use it where special rules hold sway (RHS of a variable,
{
case ':':
++p;
- wtype = w_dcolon;
+ if (p[1] != '=')
+ wtype = w_dcolon;
+ else
+ {
+ wtype = w_varassign;
+ ++p;
+ }
break;
case '=':
case '+':
case '?':
+ case '!':
if (*p == '=')
{
++p;
/* This is some non-operator word. A word consists of the longest
string of characters that doesn't contain whitespace, one of [:=#],
- or [?+]=, or one of the chars in the DELIM string. */
+ or [?+!]=, or one of the chars in the DELIM string. */
/* We start out assuming a static word; if we see a variable we'll
adjust our assumptions then. */
case ':':
#ifdef HAVE_DOS_PATHS
- /* A word CAN include a colon in its drive spec. The drive
- spec is allowed either at the beginning of a word, or as part
- of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */
- if (!(p - beg >= 2
- && (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2])
- && (p - beg == 2 || p[-3] == '(')))
+ /* A word CAN include a colon in its drive spec. The drive
+ spec is allowed either at the beginning of a word, or as part
+ of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */
+ if (!(p - beg >= 2
+ && (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2])
+ && (p - beg == 2 || p[-3] == '(')))
#endif
- goto done_word;
+ goto done_word;
case '$':
c = *(p++);
void
construct_include_path (const char **arg_dirs)
{
-#ifdef VAXC /* just don't ask ... */
+#ifdef VAXC /* just don't ask ... */
stat_t stbuf;
#else
struct stat stbuf;
if (arg_dirs)
while (*arg_dirs != 0)
{
- const char *dir = *(arg_dirs++);
+ const char *dir = *(arg_dirs++);
char *expanded = 0;
int e;
- if (dir[0] == '~')
- {
- expanded = tilde_expand (dir);
- if (expanded != 0)
- dir = expanded;
- }
+ if (dir[0] == '~')
+ {
+ expanded = tilde_expand (dir);
+ if (expanded != 0)
+ dir = expanded;
+ }
EINTRLOOP (e, stat (dir, &stbuf));
- if (e == 0 && S_ISDIR (stbuf.st_mode))
+ if (e == 0 && S_ISDIR (stbuf.st_mode))
{
unsigned int len = strlen (dir);
/* If dir name is written with trailing slashes, discard them. */
dirs[idx++] = strcache_add_len (dir, len);
}
- if (expanded)
- free (expanded);
+ if (expanded)
+ free (expanded);
}
/* Now add the standard default dirs at the end. */
if (djdir)
{
unsigned int len = strlen (djdir->value) + 8;
- char *defdir = alloca (len + 1);
+ char *defdir = alloca (len + 1);
- strcat (strcpy (defdir, djdir->value), "/include");
- dirs[idx++] = strcache_add (defdir);
+ strcat (strcpy (defdir, djdir->value), "/include");
+ dirs[idx++] = strcache_add (defdir);
if (len > max_incl_len)
max_incl_len = len;
int is_variable;
{
- /* Turn off --warn-undefined-variables while we expand HOME. */
- int save = warn_undefined_variables_flag;
- warn_undefined_variables_flag = 0;
+ /* Turn off --warn-undefined-variables while we expand HOME. */
+ int save = warn_undefined_variables_flag;
+ warn_undefined_variables_flag = 0;
- home_dir = allocated_variable_expand ("$(HOME)");
+ home_dir = allocated_variable_expand ("$(HOME)");
- warn_undefined_variables_flag = save;
+ warn_undefined_variables_flag = save;
}
is_variable = home_dir[0] != '\0';
if (!is_variable)
- {
- free (home_dir);
- home_dir = getenv ("HOME");
- }
+ {
+ free (home_dir);
+ home_dir = getenv ("HOME");
+ }
# if !defined(_AMIGA) && !defined(WINDOWS32)
if (home_dir == 0 || home_dir[0] == '\0')
- {
- extern char *getlogin ();
- char *logname = getlogin ();
- home_dir = 0;
- if (logname != 0)
- {
- struct passwd *p = getpwnam (logname);
- if (p != 0)
- home_dir = p->pw_dir;
- }
- }
+ {
+ extern char *getlogin ();
+ char *logname = getlogin ();
+ home_dir = 0;
+ if (logname != 0)
+ {
+ struct passwd *p = getpwnam (logname);
+ if (p != 0)
+ home_dir = p->pw_dir;
+ }
+ }
# endif /* !AMIGA && !WINDOWS32 */
if (home_dir != 0)
- {
- char *new = xstrdup (concat (2, home_dir, name + 1));
- if (is_variable)
- free (home_dir);
- return new;
- }
+ {
+ char *new = xstrdup (concat (2, home_dir, name + 1));
+ if (is_variable)
+ free (home_dir);
+ return new;
+ }
}
# if !defined(_AMIGA) && !defined(WINDOWS32)
else
struct passwd *pwent;
char *userend = strchr (name + 1, '/');
if (userend != 0)
- *userend = '\0';
+ *userend = '\0';
pwent = getpwnam (name + 1);
if (pwent != 0)
- {
- if (userend == 0)
- return xstrdup (pwent->pw_dir);
- else
- return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1));
- }
+ {
+ if (userend == 0)
+ return xstrdup (pwent->pw_dir);
+ else
+ return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1));
+ }
else if (userend != 0)
- *userend = '/';
+ *userend = '/';
}
# endif /* !AMIGA && !WINDOWS32 */
#endif /* !VMS */
*/
void *
-parse_file_seq (char **stringp, unsigned int size, int stopchar,
+parse_file_seq (char **stringp, unsigned int size, int stopmap,
const char *prefix, int flags)
{
extern void dir_setup_glob (glob_t *glob);
/* tmp points to tmpbuf after the prefix, if any.
tp is the end of the buffer. */
static char *tmpbuf = NULL;
- static int tmpbuf_len = 0;
- int cachep = (! (flags & PARSEFS_NOCACHE));
+ int cachep = NONE_SET (flags, PARSEFS_NOCACHE);
struct nameseq *new = 0;
struct nameseq **newp = &new;
glob_t gl;
char *tp;
-#ifdef VMS
-# define VMS_COMMA ','
-#else
-# define VMS_COMMA 0
-#endif
+ /* Always stop on NUL. */
+ stopmap |= MAP_NUL;
if (size < sizeof (struct nameseq))
size = sizeof (struct nameseq);
- if (! (flags & PARSEFS_NOGLOB))
+ if (NONE_SET (flags, PARSEFS_NOGLOB))
dir_setup_glob (&gl);
/* Get enough temporary space to construct the largest possible target. */
{
+ static int tmpbuf_len = 0;
int l = strlen (*stringp) + 1;
if (l > tmpbuf_len)
{
const char *name;
const char **nlist = 0;
char *tildep = 0;
+ int globme = 1;
#ifndef NO_ARCHIVES
char *arname = 0;
char *memname = 0;
/* Skip whitespace; at the end of the string or STOPCHAR we're done. */
p = next_token (p);
- if (*p == '\0' || *p == stopchar)
- break;
+ if (STOP_SET (*p, stopmap))
+ break;
/* There are names left, so find the end of the next name.
Throughout this iteration S points to the start. */
s = p;
- p = find_char_unquote (p, stopchar, VMS_COMMA, 1, 0);
+ p = find_char_unquote (p, stopmap|MAP_VMSCOMMA|MAP_BLANK);
#ifdef VMS
- /* convert comma separated list to space separated */
+ /* convert comma separated list to space separated */
if (p && *p == ',')
- *p =' ';
+ *p =' ';
#endif
#ifdef _AMIGA
- if (stopchar == ':' && p && *p == ':'
+ if (p && STOP_SET (*p, stopmap & MAP_COLON)
&& !(isspace ((unsigned char)p[1]) || !p[1]
|| isspace ((unsigned char)p[-1])))
- p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0);
+ p = find_char_unquote (p+1, stopmap|MAP_VMSCOMMA|MAP_BLANK);
#endif
#ifdef HAVE_DOS_PATHS
/* For DOS paths, skip a "C:\..." or a "C:/..." until we find the
first colon which isn't followed by a slash or a backslash.
Note that tokens separated by spaces should be treated as separate
tokens since make doesn't allow path names with spaces */
- if (stopchar == ':')
+ if (stopmap | MAP_COLON)
while (p != 0 && !isspace ((unsigned char)*p) &&
(p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1]))
- p = find_char_unquote (p + 1, stopchar, VMS_COMMA, 1, 0);
+ p = find_char_unquote (p + 1, stopmap|MAP_VMSCOMMA|MAP_BLANK);
#endif
if (p == 0)
- p = s + strlen (s);
+ p = s + strlen (s);
/* Strip leading "this directory" references. */
- if (! (flags & PARSEFS_NOSTRIP))
+ if (NONE_SET (flags, PARSEFS_NOSTRIP))
#ifdef VMS
- /* Skip leading `[]'s. */
- while (p - s > 2 && s[0] == '[' && s[1] == ']')
+ /* Skip leading '[]'s. */
+ while (p - s > 2 && s[0] == '[' && s[1] == ']')
#else
- /* Skip leading `./'s. */
- while (p - s > 2 && s[0] == '.' && s[1] == '/')
+ /* Skip leading './'s. */
+ while (p - s > 2 && s[0] == '.' && s[1] == '/')
#endif
- {
+ {
/* Skip "./" and all following slashes. */
- s += 2;
- while (*s == '/')
- ++s;
- }
+ s += 2;
+ while (*s == '/')
+ ++s;
+ }
/* Extract the filename just found, and skip it.
Set NAME to the string, and NLEN to its length. */
if (s == p)
{
- /* The name was stripped to empty ("./"). */
+ /* The name was stripped to empty ("./"). */
#if defined(VMS)
continue;
#elif defined(_AMIGA)
#endif
}
else
- {
+ {
#ifdef VMS
/* VMS filenames can have a ':' in them but they have to be '\'ed but we need
* to remove this '\' before we can use the filename.
* xstrdup called because S may be read-only string constant.
*/
- char *n = tp;
- while (s < p)
- {
- if (s[0] == '\\' && s[1] == ':')
+ char *n = tp;
+ while (s < p)
+ {
+ if (s[0] == '\\' && s[1] == ':')
++s;
- *(n++) = *(s++);
- }
+ *(n++) = *(s++);
+ }
n[0] = '\0';
nlen = strlen (tp);
#else
"libf.a(x.o) libf.a(y.o) libf.a(z.o)"
TP == TMP means we're not already in an archive group. Ignore
- something starting with `(', as that cannot actually be an
+ something starting with '(', as that cannot actually be an
archive-member reference (and treating it as such results in an empty
file name, which causes much lossage). Also if it ends in ")" then
it's a complete reference so we don't need to treat it specially.
Finally, note that archive groups must end with ')' as the last
character, so ensure there's some word ending like that before
considering this an archive group. */
- if (! (flags & PARSEFS_NOAR)
+ if (NONE_SET (flags, PARSEFS_NOAR)
&& tp == tmpbuf && tp[0] != '(' && tp[nlen-1] != ')')
{
char *n = strchr (tp, '(');
{
/* This looks like the first element in an open archive group.
A valid group MUST have ')' as the last character. */
- const char *e = p + nlen;
+ const char *e = p;
do
{
+ const char *o = e;
e = next_token (e);
/* Find the end of this word. We don't want to unquote and
we don't care about quoting since we're looking for the
last char in the word. */
- while (*e != '\0' && *e != stopchar && *e != VMS_COMMA
- && ! isblank ((unsigned char) *e))
+ while (! STOP_SET (*e, stopmap|MAP_BLANK|MAP_VMSCOMMA))
++e;
+ /* If we didn't move, we're done now. */
+ if (e == o)
+ break;
if (e[-1] == ')')
{
/* Found the end, so this is the first element in an
nlen -= (n + 1) - tp;
tp = n + 1;
- /* If we have just "lib(", part of something like
- "lib( a b)", go to the next item. */
- if (! nlen)
- continue;
-
/* We can stop looking now. */
break;
}
}
while (*e != '\0');
+
+ /* If we have just "lib(", part of something like "lib( a b)",
+ go to the next item. */
+ if (! nlen)
+ continue;
}
}
/* If we're not globbing we're done: add it to the end of the chain.
Go to the next item in the string. */
- if (flags & PARSEFS_NOGLOB)
+ if (ANY_SET (flags, PARSEFS_NOGLOB))
{
- NEWELT (concat (2, prefix, tp));
+ NEWELT (concat (2, prefix, tmpbuf));
continue;
}
/* If we get here we know we're doing glob expansion.
TP is a string in tmpbuf. NLEN is no longer used.
We may need to do more work: after this NAME will be set. */
- name = tp;
+ name = tmpbuf;
/* Expand tilde if applicable. */
- if (tp[0] == '~')
- {
- tildep = tilde_expand (tp);
- if (tildep != 0)
+ if (tmpbuf[0] == '~')
+ {
+ tildep = tilde_expand (tmpbuf);
+ if (tildep != 0)
name = tildep;
- }
+ }
#ifndef NO_ARCHIVES
/* If NAME is an archive member reference replace it with the archive
file name, and save the member name in MEMNAME. We will glob on the
archive name and then reattach MEMNAME later. */
- if (! (flags & PARSEFS_NOAR) && ar_name (name))
- {
- ar_parse_name (name, &arname, &memname);
- name = arname;
- }
+ if (NONE_SET (flags, PARSEFS_NOAR) && ar_name (name))
+ {
+ ar_parse_name (name, &arname, &memname);
+ name = arname;
+ }
#endif /* !NO_ARCHIVES */
- switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
- {
- case GLOB_NOSPACE:
- fatal (NILF, _("virtual memory exhausted"));
+ /* glob() is expensive: don't call it unless we need to. */
+ if (NONE_SET (flags, PARSEFS_EXISTS) && strpbrk (name, "?*[") == NULL)
+ {
+ globme = 0;
+ i = 1;
+ nlist = &name;
+ }
+ else
+ switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl))
+ {
+ case GLOB_NOSPACE:
+ fatal (NILF, _("virtual memory exhausted"));
- case 0:
- /* Success. */
- i = gl.gl_pathc;
- nlist = (const char **)gl.gl_pathv;
- break;
+ case 0:
+ /* Success. */
+ i = gl.gl_pathc;
+ nlist = (const char **)gl.gl_pathv;
+ break;
- case GLOB_NOMATCH:
- /* If we want only existing items, skip this one. */
- if (flags & PARSEFS_EXISTS)
- {
- i = 0;
- break;
- }
- /* FALLTHROUGH */
+ case GLOB_NOMATCH:
+ /* If we want only existing items, skip this one. */
+ if (ANY_SET (flags, PARSEFS_EXISTS))
+ {
+ i = 0;
+ break;
+ }
+ /* FALLTHROUGH */
- default:
- /* By default keep this name. */
- i = 1;
- nlist = &name;
- break;
- }
+ default:
+ /* By default keep this name. */
+ i = 1;
+ nlist = &name;
+ break;
+ }
/* For each matched element, add it to the list. */
while (i-- > 0)
else
{
/* We got a chain of items. Attach them. */
- (*newp)->next = found;
+ if (*newp)
+ (*newp)->next = found;
+ else
+ *newp = found;
/* Find and set the new end. Massage names if necessary. */
while (1)
#endif /* !NO_ARCHIVES */
NEWELT (concat (2, prefix, nlist[i]));
- globfree (&gl);
+ if (globme)
+ globfree (&gl);
#ifndef NO_ARCHIVES
if (arname)