return ptr + length;
}
-/* Return a pointer to the beginning of the variable buffer. */
+/* Return a pointer to the beginning of the variable buffer.
+ This is called from main() and it should never be null afterward. */
-static char *
-initialize_variable_output (void)
+char *
+initialize_variable_output ()
{
/* If we don't have a variable output buffer yet, get one. */
if (length == 0)
{
variable_buffer_output (o, "", 1);
- return (variable_buffer);
+ return variable_buffer;
}
/* We need a copy of STRING: due to eval, it's possible that it will get
if (stem)
{
const char *pattern = "%";
- char *buffer = variable_expand ("");
struct dep *dp = deps, *dl = 0;
while (dp != 0)
if (stem[0] == '\0')
{
memmove (percent, percent+1, strlen (percent));
- o = variable_buffer_output (buffer, nm, strlen (nm) + 1);
+ o = variable_buffer_output (variable_buffer, nm,
+ strlen (nm) + 1);
}
else
- o = patsubst_expand_pat (buffer, stem, pattern, nm,
+ o = patsubst_expand_pat (variable_buffer, stem, pattern, nm,
pattern+1, percent+1);
/* If the name expanded to the empty string, ignore it. */
- if (buffer[0] == '\0')
+ if (variable_buffer[0] == '\0')
{
struct dep *df = dp;
if (dp == deps)
}
/* Save the name. */
- dp->name = strcache_add_len (buffer, o - buffer);
+ dp->name = strcache_add_len (variable_buffer,
+ o - variable_buffer);
}
dp->stem = stem;
dp->staticpattern = 1;
"$*" so they'll expand properly. */
if (d->staticpattern)
{
- char *o = variable_expand ("");
- o = subst_expand (o, name, "%", "$*", 1, 2, 0);
+ char *o = subst_expand (variable_buffer, name, "%", "$*", 1, 2, 0);
*o = '\0';
free (name);
d->name = name = xstrdup (variable_buffer);
no_default_sh_exe = 1;
#endif
+ initialize_variable_output ();
+
/* Useful for attaching debuggers, etc. */
SPIN ("main-entry");
if (pattern)
{
static const char *percent = "%";
- char *buffer = variable_expand ("");
- char *o = patsubst_expand_pat (buffer, name, pattern, percent,
- pattern_percent+1, percent+1);
- f->stem = strcache_add_len (buffer, o - buffer);
+ char *o = patsubst_expand_pat (variable_buffer, name, pattern,
+ percent, pattern_percent+1, percent+1);
+ f->stem = strcache_add_len (variable_buffer, o - variable_buffer);
if (this)
{
if (! this->need_2nd_expansion)
static size_t buflen = 0;
static size_t libdir_maxlen = 0;
static unsigned int std_dirs = 0;
- char *libbuf = variable_expand ("");
+ char *libbuf;
/* Expand the pattern using LIB as a replacement. */
{
p[len] = c;
continue;
}
- p4 = variable_buffer_output (libbuf, p, p3-p);
+ p4 = variable_buffer_output (variable_buffer, p, p3-p);
p4 = variable_buffer_output (p4, lib, liblen);
p4 = variable_buffer_output (p4, p3+1, len - (p3-p));
p[len] = c;
+
+ libbuf = variable_buffer;
}
/* Look first for 'libNAME.a' in the current directory. */
allocated_variable_expand_for_file (line, (struct file *) 0)
char *expand_argument (const char *str, const char *end);
char *variable_expand_string (char *line, const char *string, size_t length);
+char *initialize_variable_output ();
void install_variable_buffer (char **bufp, size_t *lenp);
void restore_variable_buffer (char *buf, size_t len);