From: Ben Gras Date: Thu, 1 Oct 2009 11:29:08 +0000 (+0000) Subject: implement VAR += .. feature, contributed by Pieter Hijma X-Git-Tag: v3.1.5~54 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=cee82da8929f8283928ff7be5f346dc03d0a1820;p=minix.git implement VAR += .. feature, contributed by Pieter Hijma --- diff --git a/commands/make/h.h b/commands/make/h.h index a009f3a2c..ed1072ca0 100755 --- a/commands/make/h.h +++ b/commands/make/h.h @@ -277,6 +277,7 @@ _PROTOTYPE(void input, (FILE *fd )); _PROTOTYPE(struct macro *getmp, (char *name )); _PROTOTYPE(char *getmacro, (char *name )); _PROTOTYPE(struct macro *setmacro, (char *name, char *val )); +_PROTOTYPE(struct macro *addmacro, (char *name, char *val )); _PROTOTYPE(void setDFmacro, (char *name, char *val )); _PROTOTYPE(void doexp, (struct str *to, char *from )); _PROTOTYPE(void expand, (struct str *strs )); diff --git a/commands/make/input.c b/commands/make/input.c index 9eb2a8298..e167cc061 100755 --- a/commands/make/input.c +++ b/commands/make/input.c @@ -308,6 +308,36 @@ FILE *fd; while (isspace(*p)) p++; /* Find first target */ + while (((q = strchr(p, '+')) != (char *)0) && + (q[1] == '=') && (p != q) && (q[-1] == '\\')) /* Find value */ + { + a = q - 1; /* Del \ chr; move rest back */ + p = q; + while(*a++ = *q++) + ; + } + + if (q != (char *)0 && q[1] == '=') { + + *q++ = '\0'; /* Separate name and val */ + *q++ = '\0'; /* Separate name and val */ + while (isspace(*q)) + q++; + if (p = strrchr(q, '\n')) + *p = '\0'; + + p = str1; + if ((a = gettok(&p)) == (char *)0) + error("No macro name",(char *)0); + + addmacro(a, q); + + if (getline(&str1s, fd)) + return; + continue; + } + + while (((q = strchr(p, '=')) != (char *)0) && (p != q) && (q[-1] == '\\')) /* Find value */ { diff --git a/commands/make/macro.c b/commands/make/macro.c index 2afd93b9d..5c7737d8b 100755 --- a/commands/make/macro.c +++ b/commands/make/macro.c @@ -47,6 +47,41 @@ char *name; } +struct macro *addmacro(name, val) +char *name; +char *val; +{ + register struct macro *rp; + register char *cp; + int len_old_value; + + + /* Replace macro definition if it exists */ + for (rp = macrohead; rp; rp = rp->m_next) + if (strcmp(name, rp->m_name) == 0) { + if(rp->m_flag & M_OVERRIDE) return rp; /* mustn't change */ + break; + } + + if (!rp) /* If not defined, allocate space for new */ + { + fatal("Cannot add to a non-existing macro",(char *)0,0); + } + + len_old_value = strlen(rp->m_val); + if ((cp = (char *) malloc(len_old_value+1+strlen(val)+1)) == (char *)0) + fatal("No memory for macro",(char *)0,0); + strcpy(cp, rp->m_val); /* Copy in old value */ + cp[len_old_value] = ' '; + strcpy(cp+len_old_value+1, val); /* Copy in new value */ + free(rp->m_val); + rp->m_val = cp; + + return rp; +} + + + struct macro *setmacro(name, val) char *name; char *val;