mirror of
https://github.com/mirror/make.git
synced 2025-03-26 12:04:42 +08:00
Create a new CSTRLEN (constant string length) macro, and use it.
This commit is contained in:
parent
eb632d7676
commit
76827d7c10
@ -1,5 +1,11 @@
|
|||||||
2012-03-04 Paul Smith <psmith@gnu.org>
|
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
|
* expand.c (variable_append): If the current set is local and the
|
||||||
next one is not a parent, then treat the next set as
|
next one is not a parent, then treat the next set as
|
||||||
local as well. Fixes Savannah bug #35468.
|
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;
|
int doneany =0;
|
||||||
unsigned int len=0;
|
unsigned int len=0;
|
||||||
|
|
||||||
int is_suffix = streq (funcname, "suffix");
|
int is_suffix = funcname[0] == 's';
|
||||||
int is_notdir = !is_suffix;
|
int is_notdir = !is_suffix;
|
||||||
while ((p2 = find_next_token (&list_iterator, &len)) != 0)
|
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
|
#ifdef HAVE_DOS_PATHS
|
||||||
/* Handle the case of "d:foo/bar". */
|
/* 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;
|
p = p2 + 2;
|
||||||
o = variable_buffer_output (o, p, len - (p - p2));
|
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. */
|
/* Expand the argument. */
|
||||||
const char *p3 = argv[0];
|
const char *p3 = argv[0];
|
||||||
const char *p2;
|
const char *p2;
|
||||||
int doneany=0;
|
int doneany = 0;
|
||||||
unsigned int len=0;
|
unsigned int len = 0;
|
||||||
|
|
||||||
int is_basename= streq (funcname, "basename");
|
int is_basename = funcname[0] == 'b';
|
||||||
int is_dir= !is_basename;
|
int is_dir = !is_basename;
|
||||||
|
|
||||||
while ((p2 = find_next_token (&p3, &len)) != 0)
|
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]);
|
int fixlen = strlen (argv[0]);
|
||||||
const char *list_iterator = argv[1];
|
const char *list_iterator = argv[1];
|
||||||
int is_addprefix = streq (funcname, "addprefix");
|
int is_addprefix = funcname[3] == 'p';
|
||||||
int is_addsuffix = !is_addprefix;
|
int is_addsuffix = !is_addprefix;
|
||||||
|
|
||||||
int doneany = 0;
|
int doneany = 0;
|
||||||
@ -918,7 +918,7 @@ func_filter_filterout (char *o, char **argv, const char *funcname)
|
|||||||
struct a_pattern *pp;
|
struct a_pattern *pp;
|
||||||
|
|
||||||
struct hash_table a_word_table;
|
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 *pat_iterator = argv[0];
|
||||||
const char *word_iterator = argv[1];
|
const char *word_iterator = argv[1];
|
||||||
int literals = 0;
|
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.
|
equality. Return is string-boolean, ie, the empty string is false.
|
||||||
*/
|
*/
|
||||||
static char *
|
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]);
|
int result = ! strcmp (argv[0], argv[1]);
|
||||||
o = variable_buffer_output (o, result ? "1" : "", result);
|
o = variable_buffer_output (o, result ? "1" : "", result);
|
||||||
@ -1925,7 +1925,7 @@ func_eq (char *o, char **argv, char *funcname)
|
|||||||
string-boolean not operator.
|
string-boolean not operator.
|
||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
func_not (char *o, char **argv, char *funcname)
|
func_not (char *o, char **argv, char *funcname UNUSED)
|
||||||
{
|
{
|
||||||
const char *s = argv[0];
|
const char *s = argv[0];
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
30
main.c
30
main.c
@ -1528,7 +1528,7 @@ main (int argc, char **argv, char **envp)
|
|||||||
)
|
)
|
||||||
tmpdir = DEFAULT_TMPDIR;
|
tmpdir = DEFAULT_TMPDIR;
|
||||||
|
|
||||||
template = alloca (strlen (tmpdir) + sizeof (DEFAULT_TMPFILE) + 1);
|
template = alloca (strlen (tmpdir) + CSTRLEN (DEFAULT_TMPFILE) + 2);
|
||||||
strcpy (template, tmpdir);
|
strcpy (template, tmpdir);
|
||||||
|
|
||||||
#ifdef HAVE_DOS_PATHS
|
#ifdef HAVE_DOS_PATHS
|
||||||
@ -1638,7 +1638,7 @@ main (int argc, char **argv, char **envp)
|
|||||||
{
|
{
|
||||||
char *p, *value;
|
char *p, *value;
|
||||||
unsigned int i;
|
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)
|
||||||
{
|
{
|
||||||
@ -1652,7 +1652,7 @@ main (int argc, char **argv, char **envp)
|
|||||||
for (i = 0; i < eval_strings->idx; ++i)
|
for (i = 0; i < eval_strings->idx; ++i)
|
||||||
{
|
{
|
||||||
strcpy (p, "--eval=");
|
strcpy (p, "--eval=");
|
||||||
p += strlen (p);
|
p += CSTRLEN ("--eval=");
|
||||||
p = quote_for_env (p, eval_strings->list[i]);
|
p = quote_for_env (p, eval_strings->list[i]);
|
||||||
*(p++) = ' ';
|
*(p++) = ' ';
|
||||||
}
|
}
|
||||||
@ -1846,12 +1846,11 @@ main (int argc, char **argv, char **envp)
|
|||||||
cp = xmalloc (MAX_PATH + 1);
|
cp = xmalloc (MAX_PATH + 1);
|
||||||
strcpy (cp, get_jobserver_semaphore_name());
|
strcpy (cp, get_jobserver_semaphore_name());
|
||||||
#else
|
#else
|
||||||
cp = xmalloc ((sizeof ("1024")*2)+1);
|
cp = xmalloc ((CSTRLEN ("1024") * 2) + 2);
|
||||||
sprintf (cp, "%d,%d", job_fds[0], job_fds[1]);
|
sprintf (cp, "%d,%d", job_fds[0], job_fds[1]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
jobserver_fds = (struct stringlist *)
|
jobserver_fds = xmalloc (sizeof (struct stringlist));
|
||||||
xmalloc (sizeof (struct stringlist));
|
|
||||||
jobserver_fds->list = xmalloc (sizeof (char *));
|
jobserver_fds->list = xmalloc (sizeof (char *));
|
||||||
jobserver_fds->list[0] = cp;
|
jobserver_fds->list[0] = cp;
|
||||||
jobserver_fds->idx = 1;
|
jobserver_fds->idx = 1;
|
||||||
@ -2149,7 +2148,7 @@ main (int argc, char **argv, char **envp)
|
|||||||
/* Reset makeflags in case they were changed. */
|
/* Reset makeflags in case they were changed. */
|
||||||
{
|
{
|
||||||
const char *pv = define_makeflags (1, 1);
|
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);
|
sprintf (p, "MAKEFLAGS=%s", pv);
|
||||||
putenv (allocated_variable_expand (p));
|
putenv (allocated_variable_expand (p));
|
||||||
}
|
}
|
||||||
@ -2625,8 +2624,7 @@ decode_switches (int argc, char **argv, int env)
|
|||||||
sl = *(struct stringlist **) cs->value_ptr;
|
sl = *(struct stringlist **) cs->value_ptr;
|
||||||
if (sl == 0)
|
if (sl == 0)
|
||||||
{
|
{
|
||||||
sl = (struct stringlist *)
|
sl = xmalloc (sizeof (struct stringlist));
|
||||||
xmalloc (sizeof (struct stringlist));
|
|
||||||
sl->max = 5;
|
sl->max = 5;
|
||||||
sl->idx = 0;
|
sl->idx = 0;
|
||||||
sl->list = xmalloc (5 * sizeof (char *));
|
sl->list = xmalloc (5 * sizeof (char *));
|
||||||
@ -2935,7 +2933,7 @@ define_makeflags (int all, int makefile)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Four more for the possible " -- ". */
|
/* Four more for the possible " -- ". */
|
||||||
flagslen += 4 + sizeof (posixref) + sizeof (evalref);
|
flagslen += 4 + CSTRLEN (posixref) + 1 + CSTRLEN (evalref) + 1;
|
||||||
|
|
||||||
#undef ADD_FLAG
|
#undef ADD_FLAG
|
||||||
|
|
||||||
@ -3018,8 +3016,8 @@ define_makeflags (int all, int makefile)
|
|||||||
p = flagstring;
|
p = flagstring;
|
||||||
else
|
else
|
||||||
*p++ = ' ';
|
*p++ = ' ';
|
||||||
memcpy (p, evalref, sizeof (evalref) - 1);
|
memcpy (p, evalref, CSTRLEN (evalref));
|
||||||
p += sizeof (evalref) - 1;
|
p += CSTRLEN (evalref);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (all && command_variables != 0)
|
if (all && command_variables != 0)
|
||||||
@ -3047,13 +3045,13 @@ define_makeflags (int all, int makefile)
|
|||||||
/* Copy in the string. */
|
/* Copy in the string. */
|
||||||
if (posix_pedantic)
|
if (posix_pedantic)
|
||||||
{
|
{
|
||||||
memcpy (p, posixref, sizeof (posixref) - 1);
|
memcpy (p, posixref, CSTRLEN (posixref));
|
||||||
p += sizeof (posixref) - 1;
|
p += CSTRLEN (posixref);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memcpy (p, ref, sizeof (ref) - 1);
|
memcpy (p, ref, CSTRLEN (ref));
|
||||||
p += sizeof (ref) - 1;
|
p += CSTRLEN (ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (p == &flagstring[1])
|
else if (p == &flagstring[1])
|
||||||
|
3
make.h
3
make.h
@ -371,7 +371,8 @@ struct floc
|
|||||||
};
|
};
|
||||||
#define NILF ((struct floc *)0)
|
#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
|
/* 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.
|
/* Compare a word, both length and contents.
|
||||||
P must point to the word to be tested, and WLEN must be the length.
|
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. */
|
/* 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 ();
|
record_waiting_files ();
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef word1eq
|
#undef word1eq
|
||||||
|
|
||||||
if (conditionals->if_cmds)
|
if (conditionals->if_cmds)
|
||||||
fatal (fstart, _("missing 'endif'"));
|
fatal (fstart, _("missing 'endif'"));
|
||||||
@ -1467,7 +1467,7 @@ conditional_line (char *line, int len, const struct floc *flocp)
|
|||||||
unsigned int o;
|
unsigned int o;
|
||||||
|
|
||||||
/* Compare a word, both length and contents. */
|
/* 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); }
|
#define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); }
|
||||||
|
|
||||||
/* Make sure this line is a conditional. */
|
/* Make sure this line is a conditional. */
|
||||||
@ -1542,7 +1542,7 @@ conditional_line (char *line, int len, const struct floc *flocp)
|
|||||||
len = p - line;
|
len = p - line;
|
||||||
|
|
||||||
/* If it's 'else' or 'endif' or an illegal conditional, fail. */
|
/* 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)
|
|| conditional_line (line, len, flocp) < 0)
|
||||||
EXTRANEOUS ();
|
EXTRANEOUS ();
|
||||||
else
|
else
|
||||||
|
@ -235,4 +235,4 @@ struct pattern_var *create_pattern_var (const char *target,
|
|||||||
extern int export_all_variables;
|
extern int export_all_variables;
|
||||||
|
|
||||||
#define MAKELEVEL_NAME "MAKELEVEL"
|
#define MAKELEVEL_NAME "MAKELEVEL"
|
||||||
#define MAKELEVEL_LENGTH (sizeof (MAKELEVEL_NAME) - 1)
|
#define MAKELEVEL_LENGTH (CSTRLEN (MAKELEVEL_NAME))
|
||||||
|
Loading…
Reference in New Issue
Block a user