implement VAR += .. feature, contributed by Pieter Hijma
This commit is contained in:
parent
49808dcf77
commit
cee82da892
@ -277,6 +277,7 @@ _PROTOTYPE(void input, (FILE *fd ));
|
|||||||
_PROTOTYPE(struct macro *getmp, (char *name ));
|
_PROTOTYPE(struct macro *getmp, (char *name ));
|
||||||
_PROTOTYPE(char *getmacro, (char *name ));
|
_PROTOTYPE(char *getmacro, (char *name ));
|
||||||
_PROTOTYPE(struct macro *setmacro, (char *name, char *val ));
|
_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 setDFmacro, (char *name, char *val ));
|
||||||
_PROTOTYPE(void doexp, (struct str *to, char *from ));
|
_PROTOTYPE(void doexp, (struct str *to, char *from ));
|
||||||
_PROTOTYPE(void expand, (struct str *strs ));
|
_PROTOTYPE(void expand, (struct str *strs ));
|
||||||
|
@ -308,6 +308,36 @@ FILE *fd;
|
|||||||
while (isspace(*p)) p++; /* Find first target */
|
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) &&
|
while (((q = strchr(p, '=')) != (char *)0) &&
|
||||||
(p != q) && (q[-1] == '\\')) /* Find value */
|
(p != q) && (q[-1] == '\\')) /* Find value */
|
||||||
{
|
{
|
||||||
|
@ -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)
|
struct macro *setmacro(name, val)
|
||||||
char *name;
|
char *name;
|
||||||
char *val;
|
char *val;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user