summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2012-03-04 08:58:44 +0000
committerPaul Smith <psmith@gnu.org>2012-03-04 08:58:44 +0000
commit76827d7c10c2708a3147171b02bfe3981492a38f (patch)
tree1e60aeb7b2ab1bc2573b9d436b539b0f6f52f160
parenteb632d7676e92fd5750413ab6a6d16f3a6fda5c4 (diff)
downloadgunmake-76827d7c10c2708a3147171b02bfe3981492a38f.tar.gz
Create a new CSTRLEN (constant string length) macro, and use it.
-rw-r--r--ChangeLog6
-rw-r--r--function.c20
-rw-r--r--main.c30
-rw-r--r--make.h3
-rw-r--r--read.c8
-rw-r--r--variable.h2
6 files changed, 37 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index c7ea498..ff84a98 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
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.
diff --git a/function.c b/function.c
index bba9d61..a914e3f 100644
--- a/function.c
+++ b/function.c
@@ -525,7 +525,7 @@ func_notdir_suffix (char *o, char **argv, const char *funcname)
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)
{
@@ -549,7 +549,7 @@ func_notdir_suffix (char *o, char **argv, const char *funcname)
}
#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));
@@ -579,11 +579,11 @@ func_basename_dir (char *o, char **argv, const char *funcname)
/* 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)
{
@@ -634,7 +634,7 @@ func_addsuffix_addprefix (char *o, char **argv, const char *funcname)
{
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;
@@ -918,7 +918,7 @@ func_filter_filterout (char *o, char **argv, const char *funcname)
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;
@@ -1913,7 +1913,7 @@ func_shell (char *o, char **argv, const char *funcname UNUSED)
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);
@@ -1925,7 +1925,7 @@ func_eq (char *o, char **argv, char *funcname)
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;
diff --git a/main.c b/main.c
index ce10ff0..ab46460 100644
--- a/main.c
+++ b/main.c
@@ -1528,7 +1528,7 @@ main (int argc, char **argv, char **envp)
)
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
@@ -1638,7 +1638,7 @@ main (int argc, char **argv, char **envp)
{
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)
{
@@ -1652,7 +1652,7 @@ main (int argc, char **argv, char **envp)
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++) = ' ';
}
@@ -1846,12 +1846,11 @@ main (int argc, char **argv, char **envp)
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;
@@ -2149,7 +2148,7 @@ main (int argc, char **argv, char **envp)
/* 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));
}
@@ -2625,8 +2624,7 @@ decode_switches (int argc, char **argv, int env)
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 *));
@@ -2935,7 +2933,7 @@ define_makeflags (int all, int makefile)
}
/* Four more for the possible " -- ". */
- flagslen += 4 + sizeof (posixref) + sizeof (evalref);
+ flagslen += 4 + CSTRLEN (posixref) + 1 + CSTRLEN (evalref) + 1;
#undef ADD_FLAG
@@ -3018,8 +3016,8 @@ define_makeflags (int all, int makefile)
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)
@@ -3047,13 +3045,13 @@ define_makeflags (int all, int makefile)
/* 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])
diff --git a/make.h b/make.h
index f890363..74b7555 100644
--- a/make.h
+++ b/make.h
@@ -371,7 +371,8 @@ struct floc
};
#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)
/* We have to have stdarg.h or varargs.h AND v*printf or doprnt to use
diff --git a/read.c b/read.c
index 5145dff..51e345b 100644
--- a/read.c
+++ b/read.c
@@ -161,7 +161,7 @@ static char *find_char_unquote (char *string, int stop1, int stop2,
/* 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)))
/* Read in all the makefiles and return the chain of their names. */
@@ -1282,7 +1282,7 @@ eval (struct ebuffer *ebuf, int set_default)
record_waiting_files ();
}
-#undef word1eq
+#undef word1eq
if (conditionals->if_cmds)
fatal (fstart, _("missing 'endif'"));
@@ -1467,7 +1467,7 @@ conditional_line (char *line, int len, const struct floc *flocp)
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. */
@@ -1542,7 +1542,7 @@ conditional_line (char *line, int len, const struct floc *flocp)
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
diff --git a/variable.h b/variable.h
index 410c355..de841d0 100644
--- a/variable.h
+++ b/variable.h
@@ -235,4 +235,4 @@ struct pattern_var *create_pattern_var (const char *target,
extern int export_all_variables;
#define MAKELEVEL_NAME "MAKELEVEL"
-#define MAKELEVEL_LENGTH (sizeof (MAKELEVEL_NAME) - 1)
+#define MAKELEVEL_LENGTH (CSTRLEN (MAKELEVEL_NAME))