/* macro.c - macro support for gas
Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
- 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+ 2004, 2005, 2006, 2007, 2008, 2011 Free Software Foundation, Inc.
Written by Steve and Judy Chamberlain of Cygnus Support,
sac@cygnus.com
int more = get_line (ptr);
- if (to_len == 4 && strcasecmp(to, "ENDR") == 0)
+ if (to_len == 4 && strcasecmp (to, "ENDR") == 0)
{
from = NULL;
from_len = 0;
}
else
{
- char *br_buf = (char *) xmalloc(1);
+ char *br_buf = (char *) xmalloc (1);
char *in_br = br_buf;
*in_br = '\0';
&& in->ptr[idx] != tchar)
sb_add_char (out, in->ptr[idx++]);
if (idx == in->len)
- return idx;
+ {
+ free (br_buf);
+ return idx;
+ }
break;
case '(':
case '[':
--in_br;
else
{
- br_buf = (char *) xmalloc(strlen(in_br) + 2);
- strcpy(br_buf + 1, in_br);
- free(in_br);
+ br_buf = (char *) xmalloc (strlen (in_br) + 2);
+ strcpy (br_buf + 1, in_br);
+ free (in_br);
in_br = br_buf;
}
*in_br = tchar;
sb_add_char (out, tchar);
++idx;
}
- free(br_buf);
+ free (br_buf);
}
}
{
if (macro->formal_count)
--idx;
+ del_formal (formal); /* 'formal' goes out of scope. */
break;
}
idx = sb_skip_white (idx, in);
/* Doing this permits people to use & in macro bodies. */
sb_add_char (out, '&');
sb_add_sb (out, t);
+ if (src != start && in->ptr[src - 1] == '&')
+ sb_add_char (out, '&');
}
else if (copyifnotthere)
{
}
else
{
- /* FIXME: Why do we do this? */
- /* At least in alternate mode this seems correct; without this
- one can't append a literal to a parameter. */
+ /* Permit macro parameter substition delineated with
+ an '&' prefix and optional '&' suffix. */
src = sub_actual (src + 1, in, &t, formal_hash, '&', out, 0);
}
}
if (! macro
|| src + 5 >= in->len
|| strncasecmp (in->ptr + src, "LOCAL", 5) != 0
- || ! ISWHITE (in->ptr[src + 5]))
+ || ! ISWHITE (in->ptr[src + 5])
+ /* PR 11507: Skip keyword LOCAL if it is found inside a quoted string. */
+ || inquote)
{
sb_reset (&t);
src = sub_actual (src, in, &t, formal_hash,
/* Lookup the formal in the macro's list. */
ptr = (formal_entry *) hash_find (m->formal_hash, sb_terminate (&t));
if (!ptr)
- as_bad (_("Parameter named `%s' does not exist for macro `%s'"),
- t.ptr,
- m->name);
+ {
+ as_bad (_("Parameter named `%s' does not exist for macro `%s'"),
+ t.ptr,
+ m->name);
+ sb_reset (&t);
+ idx = get_any_string (idx + 1, in, &t);
+ }
else
{
/* Insert this value into the right place. */