summaryrefslogtreecommitdiff
path: root/function.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2006-11-18 20:53:44 +0000
committerPaul Smith <psmith@gnu.org>2006-11-18 20:53:44 +0000
commite4da30858037b431880263676e8f90b1f8412a38 (patch)
tree2605109d089f52e373bd976391dca85774ae3b21 /function.c
parent7595f38f62afa7ac3451018d865fb251e3ce91c3 (diff)
downloadgunmake-e4da30858037b431880263676e8f90b1f8412a38.tar.gz
Fix from Eli for incorrect value of $(MAKE) on Cygwin.
A few changes from char* to void* where appropriate, and removing of unnecessary casts. Much more work on const-ifying the codebase. This round involves some code changes to make it correct. NOTE!! There will almost certainly be problems on the non-POSIX ports that will need to be addressed after the const changes are finished: they will need to be const-ified properly and there may need to be some changes to allocate memory, etc. as well. The next (last?) big push for this, still to come, is const-ifying the filenames in struct file, struct dep, etc. This will allow us to store file names in the string cache and finally resolve Savannah bug #15182 (make uses too much memory), among other advantages.
Diffstat (limited to 'function.c')
-rw-r--r--function.c79
1 files changed, 45 insertions, 34 deletions
diff --git a/function.c b/function.c
index 39ad2fe..1dda6d8 100644
--- a/function.c
+++ b/function.c
@@ -42,22 +42,22 @@ struct function_table_entry
static unsigned long
function_table_entry_hash_1 (const void *keyv)
{
- struct function_table_entry const *key = (struct function_table_entry const *) keyv;
+ const struct function_table_entry *key = keyv;
return_STRING_N_HASH_1 (key->name, key->len);
}
static unsigned long
function_table_entry_hash_2 (const void *keyv)
{
- struct function_table_entry const *key = (struct function_table_entry const *) keyv;
+ const struct function_table_entry *key = keyv;
return_STRING_N_HASH_2 (key->name, key->len);
}
static int
function_table_entry_hash_cmp (const void *xv, const void *yv)
{
- struct function_table_entry const *x = (struct function_table_entry const *) xv;
- struct function_table_entry const *y = (struct function_table_entry const *) yv;
+ const struct function_table_entry *x = xv;
+ const struct function_table_entry *y = yv;
int result = x->len - y->len;
if (result)
return result;
@@ -277,7 +277,7 @@ lookup_function (const char *s)
/* Return 1 if PATTERN matches STR, 0 if not. */
int
-pattern_matches (char *pattern, char *percent, char *str)
+pattern_matches (const char *pattern, const char *percent, const char *str)
{
unsigned int sfxlen, strlength;
@@ -286,10 +286,10 @@ pattern_matches (char *pattern, char *percent, char *str)
unsigned int len = strlen (pattern) + 1;
char *new_chars = alloca (len);
memcpy (new_chars, pattern, len);
- pattern = new_chars;
- percent = find_percent (pattern);
+ percent = find_percent (new_chars);
if (percent == 0)
- return streq (pattern, str);
+ return streq (new_chars, str);
+ pattern = new_chars;
}
sfxlen = strlen (percent + 1);
@@ -2120,15 +2120,15 @@ expand_builtin_function (char *o, int argc, char **argv,
*STRINGP past the reference and returning nonzero. If not, return zero. */
int
-handle_function (char **op, char **stringp)
+handle_function (char **op, const char **stringp)
{
const struct function_table_entry *entry_p;
char openparen = (*stringp)[0];
char closeparen = openparen == '(' ? ')' : '}';
- char *beg;
- char *end;
+ const char *beg;
+ const char *end;
int count = 0;
- register char *p;
+ char *abeg = NULL;
char **argv, **argvp;
int nargs;
@@ -2175,36 +2175,47 @@ handle_function (char **op, char **stringp)
not, make a duplicate of the string and point into that, nul-terminating
each argument. */
- if (!entry_p->expand_args)
+ if (entry_p->expand_args)
{
- int len = end - beg;
+ const char *p;
+ for (p=beg, nargs=0; p <= end; ++argvp)
+ {
+ const char *next;
- p = xmalloc (len+1);
- memcpy (p, beg, len);
- p[len] = '\0';
- beg = p;
- end = beg + len;
- }
+ ++nargs;
- for (p=beg, nargs=0; p <= end; ++argvp)
- {
- char *next;
+ if (nargs == entry_p->maximum_args
+ || (! (next = find_next_argument (openparen, closeparen, p, end))))
+ next = end;
- ++nargs;
+ *argvp = expand_argument (p, next);
+ p = next + 1;
+ }
+ }
+ else
+ {
+ int len = end - beg;
+ char *p, *aend;
- if (nargs == entry_p->maximum_args
- || (! (next = find_next_argument (openparen, closeparen, p, end))))
- next = end;
+ abeg = xmalloc (len+1);
+ memcpy (abeg, beg, len);
+ abeg[len] = '\0';
+ aend = abeg + len;
- if (entry_p->expand_args)
- *argvp = expand_argument (p, next);
- else
+ for (p=abeg, nargs=0; p <= aend; ++argvp)
{
+ char *next;
+
+ ++nargs;
+
+ if (nargs == entry_p->maximum_args
+ || (! (next = find_next_argument (openparen, closeparen, p, aend))))
+ next = aend;
+
*argvp = p;
*next = '\0';
+ p = next + 1;
}
-
- p = next + 1;
}
*argvp = NULL;
@@ -2215,8 +2226,8 @@ handle_function (char **op, char **stringp)
if (entry_p->expand_args)
for (argvp=argv; *argvp != 0; ++argvp)
free (*argvp);
- else
- free (beg);
+ if (abeg)
+ free (abeg);
return 1;
}