* - reduced 464 bytes.
* - 64 math support
*
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* This program evaluates expressions. Each token (operator, operand,
/* The arguments given to the program, minus the program name. */
struct globals {
char **args;
-};
+} FIX_ALIASING;
#define G (*(struct globals*)&bb_common_bufsiz1)
/* forward declarations */
static VALUE *docolon(VALUE *sv, VALUE *pv)
{
+ enum { NMATCH = 2 };
VALUE *v;
regex_t re_buffer;
- const int NMATCH = 2;
regmatch_t re_regs[NMATCH];
tostring(sv);
tostring(pv);
if (pv->u.s[0] == '^') {
- bb_error_msg("\
-warning: unportable BRE: `%s': using `^' as the first character\n\
-of a basic regular expression is not portable; it is being ignored", pv->u.s);
+ bb_error_msg(
+"warning: '%s': using '^' as the first character\n"
+"of a basic regular expression is not portable; it is ignored", pv->u.s);
}
memset(&re_buffer, 0, sizeof(re_buffer));
- memset(re_regs, 0, sizeof(*re_regs));
+ memset(re_regs, 0, sizeof(re_regs));
xregcomp(&re_buffer, pv->u.s, 0);
/* expr uses an anchored pattern match, so check that there was a
&& re_regs[0].rm_so == 0
) {
/* Were \(...\) used? */
- if (re_buffer.re_nsub > 0) {
+ if (re_buffer.re_nsub > 0 && re_regs[1].rm_so >= 0) {
sv->u.s[re_regs[1].rm_eo] = '\0';
v = str_value(sv->u.s + re_regs[1].rm_so);
} else {
else
v = int_value(0);
}
-//FIXME: sounds like here is a bit missing: regfree(&re_buffer);
+ regfree(&re_buffer);
return v;
}
freev(i2);
}
return v;
-
}
/* Handle : operator (pattern matching).