var.c (103503) | var.c (103508) |
---|---|
1/* 2 * Copyright (c) 1988, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1989 by Berkeley Softworks 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Adam de Boor. --- 25 unchanged lines hidden (view full) --- 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)var.c 8.3 (Berkeley) 3/19/94 39 */ 40 41#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1988, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1989 by Berkeley Softworks 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Adam de Boor. --- 25 unchanged lines hidden (view full) --- 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)var.c 8.3 (Berkeley) 3/19/94 39 */ 40 41#include <sys/cdefs.h> |
42__FBSDID("$FreeBSD: head/usr.bin/make/var.c 103503 2002-09-17 21:29:06Z jmallett $"); | 42__FBSDID("$FreeBSD: head/usr.bin/make/var.c 103508 2002-09-17 22:31:26Z jmallett $"); |
43 44/*- 45 * var.c -- 46 * Variable-handling functions 47 * 48 * Interface: 49 * Var_Set Set the value of a variable in the given 50 * context. The variable is created if it doesn't --- 340 unchanged lines hidden (view full) --- 391 len = val ? strlen(val) : 0; 392 v->val = Buf_Init(len+1); 393 Buf_AddBytes(v->val, len, (Byte *)val); 394 395 v->flags = 0; 396 397 (void) Lst_AtFront (ctxt->context, (void *)v); 398 (void) Lst_AtEnd (allVars, (void *) v); | 43 44/*- 45 * var.c -- 46 * Variable-handling functions 47 * 48 * Interface: 49 * Var_Set Set the value of a variable in the given 50 * context. The variable is created if it doesn't --- 340 unchanged lines hidden (view full) --- 391 len = val ? strlen(val) : 0; 392 v->val = Buf_Init(len+1); 393 Buf_AddBytes(v->val, len, (Byte *)val); 394 395 v->flags = 0; 396 397 (void) Lst_AtFront (ctxt->context, (void *)v); 398 (void) Lst_AtEnd (allVars, (void *) v); |
399 if (DEBUG(VAR)) { 400 fprintf(stderr, "%s:%s = %s\n", ctxt->name, name, val); 401 } | 399 DEBUGF(VAR, "%s:%s = %s\n", ctxt->name, name, val); |
402} 403 404 405/*- 406 *----------------------------------------------------------------------- 407 * VarDelete -- 408 * Delete a variable and all the space associated with it. 409 * --- 31 unchanged lines hidden (view full) --- 441 */ 442void 443Var_Delete(name, ctxt) 444 char *name; 445 GNode *ctxt; 446{ 447 LstNode ln; 448 | 400} 401 402 403/*- 404 *----------------------------------------------------------------------- 405 * VarDelete -- 406 * Delete a variable and all the space associated with it. 407 * --- 31 unchanged lines hidden (view full) --- 439 */ 440void 441Var_Delete(name, ctxt) 442 char *name; 443 GNode *ctxt; 444{ 445 LstNode ln; 446 |
449 if (DEBUG(VAR)) { 450 fprintf(stderr, "%s:delete %s\n", ctxt->name, name); 451 } | 447 DEBUGF(VAR, "%s:delete %s\n", ctxt->name, name); |
452 ln = Lst_Find(ctxt->context, (void *)name, VarCmp); 453 if (ln != NULL) { 454 Var *v; 455 456 v = (Var *)Lst_Datum(ln); 457 Lst_Remove(ctxt->context, ln); 458 ln = Lst_Member(allVars, v); 459 Lst_Remove(allVars, ln); --- 38 unchanged lines hidden (view full) --- 498 VarPossiblyExpand(&name, ctxt); 499 v = VarFind (name, ctxt, 0); 500 if (v == (Var *) NULL) { 501 VarAdd (name, val, ctxt); 502 } else { 503 Buf_Discard(v->val, Buf_Size(v->val)); 504 Buf_AddBytes(v->val, strlen(val), (Byte *)val); 505 | 448 ln = Lst_Find(ctxt->context, (void *)name, VarCmp); 449 if (ln != NULL) { 450 Var *v; 451 452 v = (Var *)Lst_Datum(ln); 453 Lst_Remove(ctxt->context, ln); 454 ln = Lst_Member(allVars, v); 455 Lst_Remove(allVars, ln); --- 38 unchanged lines hidden (view full) --- 494 VarPossiblyExpand(&name, ctxt); 495 v = VarFind (name, ctxt, 0); 496 if (v == (Var *) NULL) { 497 VarAdd (name, val, ctxt); 498 } else { 499 Buf_Discard(v->val, Buf_Size(v->val)); 500 Buf_AddBytes(v->val, strlen(val), (Byte *)val); 501 |
506 if (DEBUG(VAR)) { 507 fprintf(stderr, "%s:%s = %s\n", ctxt->name, name, val); 508 } | 502 DEBUGF(VAR, "%s:%s = %s\n", ctxt->name, name, val); |
509 } 510 /* 511 * Any variables given on the command line are automatically exported 512 * to the environment (as per POSIX standard) 513 */ 514 if (ctxt == VAR_CMD) { 515 setenv(name, val, 1); 516 } --- 34 unchanged lines hidden (view full) --- 551 v = VarFind (name, ctxt, (ctxt == VAR_GLOBAL) ? FIND_ENV : 0); 552 553 if (v == (Var *) NULL) { 554 VarAdd (name, val, ctxt); 555 } else { 556 Buf_AddByte(v->val, (Byte)' '); 557 Buf_AddBytes(v->val, strlen(val), (Byte *)val); 558 | 503 } 504 /* 505 * Any variables given on the command line are automatically exported 506 * to the environment (as per POSIX standard) 507 */ 508 if (ctxt == VAR_CMD) { 509 setenv(name, val, 1); 510 } --- 34 unchanged lines hidden (view full) --- 545 v = VarFind (name, ctxt, (ctxt == VAR_GLOBAL) ? FIND_ENV : 0); 546 547 if (v == (Var *) NULL) { 548 VarAdd (name, val, ctxt); 549 } else { 550 Buf_AddByte(v->val, (Byte)' '); 551 Buf_AddBytes(v->val, strlen(val), (Byte *)val); 552 |
559 if (DEBUG(VAR)) { 560 fprintf(stderr, "%s:%s = %s\n", ctxt->name, name, 561 (char *) Buf_GetAll(v->val, (int *)NULL)); 562 } | 553 DEBUGF(VAR, "%s:%s = %s\n", ctxt->name, name, 554 (char *) Buf_GetAll(v->val, (int *)NULL)); |
563 564 if (v->flags & VAR_FROM_ENV) { 565 /* 566 * If the original variable came from the environment, we 567 * have to install it in the global context (we could place 568 * it in the environment, but then we should provide a way to 569 * export other variables...) 570 */ --- 1204 unchanged lines hidden (view full) --- 1775 /* 1776 * Skip initial colon while putting it back. 1777 */ 1778 *tstr++ = ':'; 1779 while (*tstr != endc) { 1780 char *newStr; /* New value to return */ 1781 char termc; /* Character which terminated scan */ 1782 | 555 556 if (v->flags & VAR_FROM_ENV) { 557 /* 558 * If the original variable came from the environment, we 559 * have to install it in the global context (we could place 560 * it in the environment, but then we should provide a way to 561 * export other variables...) 562 */ --- 1204 unchanged lines hidden (view full) --- 1767 /* 1768 * Skip initial colon while putting it back. 1769 */ 1770 *tstr++ = ':'; 1771 while (*tstr != endc) { 1772 char *newStr; /* New value to return */ 1773 char termc; /* Character which terminated scan */ 1774 |
1783 if (DEBUG(VAR)) { 1784 fprintf(stderr, "Applying :%c to \"%s\"\n", *tstr, str); 1785 } | 1775 DEBUGF(VAR, "Applying :%c to \"%s\"\n", *tstr, str); |
1786 switch (*tstr) { 1787 case 'U': 1788 if (tstr[1] == endc || tstr[1] == ':') { 1789 Buffer buf; 1790 buf = Buf_Init(MAKE_BSIZE); 1791 for (cp = str; *cp ; cp++) 1792 Buf_AddByte(buf, (Byte) toupper(*cp)); 1793 --- 452 unchanged lines hidden (view full) --- 2246 *cp != ':' && *cp != endc && *cp != '\0'; 2247 cp++) 2248 continue; 2249 termc = *cp; 2250 newStr = var_Error; 2251 } 2252 } 2253 } | 1776 switch (*tstr) { 1777 case 'U': 1778 if (tstr[1] == endc || tstr[1] == ':') { 1779 Buffer buf; 1780 buf = Buf_Init(MAKE_BSIZE); 1781 for (cp = str; *cp ; cp++) 1782 Buf_AddByte(buf, (Byte) toupper(*cp)); 1783 --- 452 unchanged lines hidden (view full) --- 2236 *cp != ':' && *cp != endc && *cp != '\0'; 2237 cp++) 2238 continue; 2239 termc = *cp; 2240 newStr = var_Error; 2241 } 2242 } 2243 } |
2254 if (DEBUG(VAR)) { 2255 fprintf(stderr, "Result is \"%s\"\n", newStr); 2256 } | 2244 DEBUGF(VAR, "Result is \"%s\"\n", newStr); |
2257 2258 if (*freePtr) { 2259 free (str); 2260 } 2261 str = newStr; 2262 if (str != var_Error) { 2263 *freePtr = TRUE; 2264 } else { --- 315 unchanged lines hidden --- | 2245 2246 if (*freePtr) { 2247 free (str); 2248 } 2249 str = newStr; 2250 if (str != var_Error) { 2251 *freePtr = TRUE; 2252 } else { --- 315 unchanged lines hidden --- |