/******************************************************************************
* @file rule.c
*****************************************************************************/
+#include <stdlib.h>
#include <string.h>
#include "command.h"
struct hashtab_name *key;
+ char *hash_tagged_name = 0;
+ char *dot = 0, *ptr = 0;
+
if (!(key = hashtab_get_key (&hashtab_rules, name))) {
- return 0;
+
+ hash_tagged_name = xstrdup (name);
+
+ /* Find the begining of the filename. */
+ if (!(ptr = strrchr (hash_tagged_name, '/'))) {
+ ptr = strrchr (hash_tagged_name, '\\');
+ }
+
+ if (!ptr) {
+ ptr = hash_tagged_name;
+ } else {
+ ptr++;
+ }
+
+ /* Replace filename by '%'. */
+ if (*ptr) {
+
+ dot = strrchr (ptr, '.');
+ *ptr++ = '%';
+
+ if (dot) {
+ memmove (ptr, dot, strlen (dot) + 1);
+ } else {
+ *ptr = '\0';
+ }
+
+ }
+
+ key = hashtab_get_key (&hashtab_rules, hash_tagged_name);
+ free (hash_tagged_name);
+
+ if (!key) {
+ return 0;
+ }
+
}
return hashtab_get (&hashtab_rules, key);
size_t rem = strlen (to_s) - strlen (from_s);
- new_body = xrealloc (new_body, strlen (new_body) + rem);
+ new_body = xrealloc (new_body, strlen (new_body) + rem + 1);
memmove (p + rem, p, strlen (p) + 1);
memcpy (p, to_s, strlen (to_s));
while (line[pos]) {
- if (line[pos] == '$') {
+ if (line[pos] == '$' || (line[pos] == '%' && variable_find ("%"))) {
char *new, *replacement = "";
char *p_after_variable;
struct builtin_function *func;
char saved_ch;
- if (line[pos + 1] == '$') {
+ if (line[pos] == '%') {
+
+ var = variable_find ("%");
+ p_after_variable = line + pos + 1;
+
+ } else if (line[pos + 1] == '$') {
p_after_variable = line + pos + 2;
pos += 1;
#if defined (unix) || defined (__unix) || defined (__unix__) || defined (__APPLE__)
# define __USE_POSIX
+#elif defined (_WIN32)
+# define strcasecmp _stricmp
#endif
#include <stdio.h>
struct dep *dep;
- char *p, *star_name, *lesser_name;
+ char *hash_name = 0, *filename = 0, *dot = 0, *n2 = 0;
int ret;
+ char *p, *star_name, *lesser_name;
+
CString str;
cstr_new (&str);
for (dep = r->deps; dep; dep = dep->next) {
- cstr_cat (&str, dep->name, strlen (dep->name));
+ if ((p = strchr (dep->name, '%'))) {
+
+ /* Replace the rule's '%' by the filename without extension. */
+ n2 = xmalloc (strlen (dep->name) + strlen (name) + 1);
+ strncat (n2, dep->name, p - dep->name);
+
+ if (!(filename = strrchr (name, '/'))) {
+ filename = strrchr (name, '\\');
+ }
+
+ if (!filename) {
+ filename = name;
+ } else {
+ filename++;
+ }
+
+ if ((dot = strrchr (filename, '.'))) {
+ strncat (n2, filename, dot - filename);
+ } else {
+ strcat (n2, filename);
+ }
+
+ strcat (n2, p + 1);
+
+ ret = rule_search_and_build (n2);
+ cstr_cat (&str, n2, strlen (n2));
+
+ free (n2);
+
+ if (ret) {
+ return ret;
+ }
+
+ } else {
+
+ cstr_cat (&str, dep->name, strlen (dep->name));
+
+ if ((ret = rule_search_and_build (dep->name))) {
+ return ret;
+ }
- if ((ret = rule_search_and_build (dep->name))) {
- return ret;
}
if (dep->next) {
*p = '\0';
}
+ if (!(filename = strrchr (name, '/'))) {
+ filename = strrchr (name, '\\');
+ }
+
+ if (!filename) {
+ filename = name;
+ } else {
+ filename++;
+ }
+
+ hash_name = xstrdup (filename);
+
+ if ((dot = strrchr (hash_name, '.'))) {
+ *dot = '\0';
+ }
+
variable_change ("@", xstrdup (name), VAR_ORIGIN_AUTOMATIC);
variable_change ("<", lesser_name, VAR_ORIGIN_AUTOMATIC);
+ variable_change ("%", hash_name, VAR_ORIGIN_AUTOMATIC);
variable_change ("*", star_name, VAR_ORIGIN_AUTOMATIC);
variable_change ("^", xstrdup (str.data), VAR_ORIGIN_AUTOMATIC);