version 1.45, 2017/01/25 14:17:45 |
version 1.46, 2017/02/24 23:38:47 |
|
|
{ |
{ |
VarPattern *pattern; |
VarPattern *pattern; |
const char *cp, *cp2; |
const char *cp, *cp2; |
BUFFER buf; |
BUFFER buf, buf2; |
int cnt = 0; |
int cnt = 0; |
char startc = endc == ')' ? '(' : '{'; |
char startc = endc == ')' ? '(' : '{'; |
|
|
|
Buf_Init(&buf, 0); |
for (cp = *p;; cp++) { |
for (cp = *p;; cp++) { |
if (*cp == '=' && cnt == 0) |
if (*cp == '=' && cnt == 0) |
break; |
break; |
if (*cp == '\0') |
if (*cp == '\0') { |
|
Buf_Destroy(&buf); |
return NULL; |
return NULL; |
|
} |
if (*cp == startc) |
if (*cp == startc) |
cnt++; |
cnt++; |
else if (*cp == endc) { |
else if (*cp == endc) { |
cnt--; |
cnt--; |
if (cnt < 0) |
if (cnt < 0) { |
|
Buf_Destroy(&buf); |
return NULL; |
return NULL; |
|
} |
|
} else if (*cp == '$') { |
|
if (cp[1] == '$') |
|
cp++; |
|
else { |
|
size_t len; |
|
(void)Var_ParseBuffer(&buf, cp, ctxt, err, |
|
&len); |
|
cp += len - 1; |
|
continue; |
|
} |
} |
} |
|
Buf_AddChar(&buf, *cp); |
} |
} |
Buf_Init(&buf, 0); |
|
|
Buf_Init(&buf2, 0); |
for (cp2 = cp+1;; cp2++) { |
for (cp2 = cp+1;; cp2++) { |
if (((*cp2 == ':' && cp2[1] != endc) || *cp2 == endc) && |
if (((*cp2 == ':' && cp2[1] != endc) || *cp2 == endc) && |
cnt == 0) |
cnt == 0) |
break; |
break; |
if (*cp2 == '\0') { |
if (*cp2 == '\0') { |
Buf_Destroy(&buf); |
Buf_Destroy(&buf); |
|
Buf_Destroy(&buf2); |
return NULL; |
return NULL; |
} |
} |
if (*cp2 == startc) |
if (*cp2 == startc) |
|
|
cnt--; |
cnt--; |
if (cnt < 0) { |
if (cnt < 0) { |
Buf_Destroy(&buf); |
Buf_Destroy(&buf); |
|
Buf_Destroy(&buf2); |
return NULL; |
return NULL; |
} |
} |
} else if (*cp2 == '$') { |
} else if (*cp2 == '$') { |
|
|
cp2++; |
cp2++; |
else { |
else { |
size_t len; |
size_t len; |
(void)Var_ParseBuffer(&buf, cp2, ctxt, err, |
(void)Var_ParseBuffer(&buf2, cp2, ctxt, err, |
&len); |
&len); |
cp2 += len - 1; |
cp2 += len - 1; |
continue; |
continue; |
} |
} |
} |
} |
Buf_AddChar(&buf, *cp2); |
Buf_AddChar(&buf2, *cp2); |
} |
} |
|
|
pattern = emalloc(sizeof(VarPattern)); |
pattern = emalloc(sizeof(VarPattern)); |
pattern->lbuffer = pattern->lhs = Str_dupi(*p, cp); |
pattern->lbuffer = pattern->lhs = Buf_Retrieve(&buf); |
pattern->leftLen = cp - *p; |
pattern->leftLen = Buf_Size(&buf); |
pattern->rhs = Buf_Retrieve(&buf); |
pattern->rhs = Buf_Retrieve(&buf2); |
pattern->rightLen = Buf_Size(&buf); |
pattern->rightLen = Buf_Size(&buf2); |
pattern->flags = 0; |
pattern->flags = 0; |
*p = cp2; |
*p = cp2; |
return pattern; |
return pattern; |