mirror of
https://git.savannah.gnu.org/git/make.git
synced 2024-11-25 04:35:44 +00:00
Create a new CSTRLEN (constant string length) macro, and use it.
This commit is contained in:
parent
eb632d7676
commit
76827d7c10
6 changed files with 37 additions and 32 deletions
|
@ -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.
|
||||
|
|
20
function.c
20
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;
|
||||
|
|
30
main.c
30
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])
|
||||
|
|
3
make.h
3
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
|
||||
|
|
8
read.c
8
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
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue