2012-03-04 Paul Smith <psmith@gnu.org>
+ * make.h (CSTRLEN): Determine the length of a constant string.
+ * main.c: Use the new macro.
+ * read.c: Ditto.
+ * variable.h: Ditto.
+ * function.c: Simplify checks for function alternatives.
+
* expand.c (variable_append): If the current set is local and the
next one is not a parent, then treat the next set as
local as well. Fixes Savannah bug #35468.
int doneany =0;
unsigned int len=0;
- int is_suffix = streq (funcname, "suffix");
+ int is_suffix = funcname[0] == 's';
int is_notdir = !is_suffix;
while ((p2 = find_next_token (&list_iterator, &len)) != 0)
{
}
#ifdef HAVE_DOS_PATHS
/* Handle the case of "d:foo/bar". */
- else if (streq (funcname, "notdir") && p2[0] && p2[1] == ':')
+ else if (is_notdir && p2[0] && p2[1] == ':')
{
p = p2 + 2;
o = variable_buffer_output (o, p, len - (p - p2));
/* Expand the argument. */
const char *p3 = argv[0];
const char *p2;
- int doneany=0;
- unsigned int len=0;
+ int doneany = 0;
+ unsigned int len = 0;
- int is_basename= streq (funcname, "basename");
- int is_dir= !is_basename;
+ int is_basename = funcname[0] == 'b';
+ int is_dir = !is_basename;
while ((p2 = find_next_token (&p3, &len)) != 0)
{
{
int fixlen = strlen (argv[0]);
const char *list_iterator = argv[1];
- int is_addprefix = streq (funcname, "addprefix");
+ int is_addprefix = funcname[3] == 'p';
int is_addsuffix = !is_addprefix;
int doneany = 0;
struct a_pattern *pp;
struct hash_table a_word_table;
- int is_filter = streq (funcname, "filter");
+ int is_filter = funcname[CSTRLEN ("filter")] == '\0';
const char *pat_iterator = argv[0];
const char *word_iterator = argv[1];
int literals = 0;
equality. Return is string-boolean, ie, the empty string is false.
*/
static char *
-func_eq (char *o, char **argv, char *funcname)
+func_eq (char *o, char **argv, char *funcname UNUSED)
{
int result = ! strcmp (argv[0], argv[1]);
o = variable_buffer_output (o, result ? "1" : "", result);
string-boolean not operator.
*/
static char *
-func_not (char *o, char **argv, char *funcname)
+func_not (char *o, char **argv, char *funcname UNUSED)
{
const char *s = argv[0];
int result = 0;
)
tmpdir = DEFAULT_TMPDIR;
- template = alloca (strlen (tmpdir) + sizeof (DEFAULT_TMPFILE) + 1);
+ template = alloca (strlen (tmpdir) + CSTRLEN (DEFAULT_TMPFILE) + 2);
strcpy (template, tmpdir);
#ifdef HAVE_DOS_PATHS
{
char *p, *value;
unsigned int i;
- unsigned int len = sizeof ("--eval=") * eval_strings->idx;
+ unsigned int len = (CSTRLEN ("--eval=") + 1) * eval_strings->idx;
for (i = 0; i < eval_strings->idx; ++i)
{
for (i = 0; i < eval_strings->idx; ++i)
{
strcpy (p, "--eval=");
- p += strlen (p);
+ p += CSTRLEN ("--eval=");
p = quote_for_env (p, eval_strings->list[i]);
*(p++) = ' ';
}
cp = xmalloc (MAX_PATH + 1);
strcpy (cp, get_jobserver_semaphore_name());
#else
- cp = xmalloc ((sizeof ("1024")*2)+1);
+ cp = xmalloc ((CSTRLEN ("1024") * 2) + 2);
sprintf (cp, "%d,%d", job_fds[0], job_fds[1]);
#endif
- jobserver_fds = (struct stringlist *)
- xmalloc (sizeof (struct stringlist));
+ jobserver_fds = xmalloc (sizeof (struct stringlist));
jobserver_fds->list = xmalloc (sizeof (char *));
jobserver_fds->list[0] = cp;
jobserver_fds->idx = 1;
/* Reset makeflags in case they were changed. */
{
const char *pv = define_makeflags (1, 1);
- char *p = alloca (sizeof ("MAKEFLAGS=") + strlen (pv) + 1);
+ char *p = alloca (CSTRLEN ("MAKEFLAGS=") + strlen (pv) + 1);
sprintf (p, "MAKEFLAGS=%s", pv);
putenv (allocated_variable_expand (p));
}
sl = *(struct stringlist **) cs->value_ptr;
if (sl == 0)
{
- sl = (struct stringlist *)
- xmalloc (sizeof (struct stringlist));
+ sl = xmalloc (sizeof (struct stringlist));
sl->max = 5;
sl->idx = 0;
sl->list = xmalloc (5 * sizeof (char *));
}
/* Four more for the possible " -- ". */
- flagslen += 4 + sizeof (posixref) + sizeof (evalref);
+ flagslen += 4 + CSTRLEN (posixref) + 1 + CSTRLEN (evalref) + 1;
#undef ADD_FLAG
p = flagstring;
else
*p++ = ' ';
- memcpy (p, evalref, sizeof (evalref) - 1);
- p += sizeof (evalref) - 1;
+ memcpy (p, evalref, CSTRLEN (evalref));
+ p += CSTRLEN (evalref);
}
if (all && command_variables != 0)
/* Copy in the string. */
if (posix_pedantic)
{
- memcpy (p, posixref, sizeof (posixref) - 1);
- p += sizeof (posixref) - 1;
+ memcpy (p, posixref, CSTRLEN (posixref));
+ p += CSTRLEN (posixref);
}
else
{
- memcpy (p, ref, sizeof (ref) - 1);
- p += sizeof (ref) - 1;
+ memcpy (p, ref, CSTRLEN (ref));
+ p += CSTRLEN (ref);
}
}
else if (p == &flagstring[1])
};
#define NILF ((struct floc *)0)
-#define STRING_SIZE_TUPLE(_s) (_s), (sizeof (_s)-1)
+#define CSTRLEN(_s) (sizeof (_s)-1)
+#define STRING_SIZE_TUPLE(_s) (_s), CSTRLEN(_s)
\f
/* We have to have stdarg.h or varargs.h AND v*printf or doprnt to use
/* 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. */
record_waiting_files ();
}
-#undef word1eq
+#undef word1eq
if (conditionals->if_cmds)
fatal (fstart, _("missing 'endif'"));
unsigned int o;
/* Compare a word, both length and contents. */
-#define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))
+#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. */
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 ();
else
extern int export_all_variables;
#define MAKELEVEL_NAME "MAKELEVEL"
-#define MAKELEVEL_LENGTH (sizeof (MAKELEVEL_NAME) - 1)
+#define MAKELEVEL_LENGTH (CSTRLEN (MAKELEVEL_NAME))