diff options
| author | Stefan Monnier | 2007-09-20 22:38:15 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2007-09-20 22:38:15 +0000 |
| commit | db699fc6b6a4e0226306af05ee6073ca3296c72d (patch) | |
| tree | 39a0b37792e8e9f1f4ce209c5adcf4dfec458542 /src | |
| parent | dc077553c9792c6886bd41f5c2af559ea75d3b8b (diff) | |
| download | emacs-db699fc6b6a4e0226306af05ee6073ca3296c72d.tar.gz emacs-db699fc6b6a4e0226306af05ee6073ca3296c72d.zip | |
(getenv_internal_1): New function.
(getenv_internal): Use it.
(Fgetenv_internal): Use it. Accept an env-list as optional arg.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 4 | ||||
| -rw-r--r-- | src/callproc.c | 159 |
2 files changed, 73 insertions, 90 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 2830f7fa376..13ae3a20dd6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,9 @@ | |||
| 1 | 2007-09-20 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2007-09-20 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * callproc.c (getenv_internal_1): New function. | ||
| 4 | (getenv_internal): Use it. | ||
| 5 | (Fgetenv_internal): Use it. Accept an env-list as optional arg. | ||
| 6 | |||
| 3 | * terminal.c (get_terminal): Don't accept integers to represent terminals. | 7 | * terminal.c (get_terminal): Don't accept integers to represent terminals. |
| 4 | (Fterminal_name, Fterminal_parameters, Fterminal_parameter) | 8 | (Fterminal_name, Fterminal_parameters, Fterminal_parameter) |
| 5 | (Fset_terminal_parameter): Work with dead terminals as well. | 9 | (Fset_terminal_parameter): Work with dead terminals as well. |
diff --git a/src/callproc.c b/src/callproc.c index bd38f381123..fafbfbffe91 100644 --- a/src/callproc.c +++ b/src/callproc.c | |||
| @@ -1512,6 +1512,45 @@ relocate_fd (fd, minfd) | |||
| 1512 | } | 1512 | } |
| 1513 | 1513 | ||
| 1514 | static int | 1514 | static int |
| 1515 | getenv_internal_1 (var, varlen, value, valuelen, env) | ||
| 1516 | char *var; | ||
| 1517 | int varlen; | ||
| 1518 | char **value; | ||
| 1519 | int *valuelen; | ||
| 1520 | Lisp_Object env; | ||
| 1521 | { | ||
| 1522 | for (; CONSP (env); env = XCDR (env)) | ||
| 1523 | { | ||
| 1524 | Lisp_Object entry = XCAR (env); | ||
| 1525 | if (STRINGP (entry) | ||
| 1526 | && SBYTES (entry) >= varlen | ||
| 1527 | #ifdef WINDOWSNT | ||
| 1528 | /* NT environment variables are case insensitive. */ | ||
| 1529 | && ! strnicmp (SDATA (entry), var, varlen) | ||
| 1530 | #else /* not WINDOWSNT */ | ||
| 1531 | && ! bcmp (SDATA (entry), var, varlen) | ||
| 1532 | #endif /* not WINDOWSNT */ | ||
| 1533 | ) | ||
| 1534 | { | ||
| 1535 | if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=') | ||
| 1536 | { | ||
| 1537 | *value = (char *) SDATA (entry) + (varlen + 1); | ||
| 1538 | *valuelen = SBYTES (entry) - (varlen + 1); | ||
| 1539 | return 1; | ||
| 1540 | } | ||
| 1541 | else if (SBYTES (entry) == varlen) | ||
| 1542 | { | ||
| 1543 | /* Lone variable names in Vprocess_environment mean that | ||
| 1544 | variable should be removed from the environment. */ | ||
| 1545 | *value = NULL; | ||
| 1546 | return 1; | ||
| 1547 | } | ||
| 1548 | } | ||
| 1549 | } | ||
| 1550 | return 0; | ||
| 1551 | } | ||
| 1552 | |||
| 1553 | static int | ||
| 1515 | getenv_internal (var, varlen, value, valuelen, frame) | 1554 | getenv_internal (var, varlen, value, valuelen, frame) |
| 1516 | char *var; | 1555 | char *var; |
| 1517 | int varlen; | 1556 | int varlen; |
| @@ -1519,42 +1558,18 @@ getenv_internal (var, varlen, value, valuelen, frame) | |||
| 1519 | int *valuelen; | 1558 | int *valuelen; |
| 1520 | Lisp_Object frame; | 1559 | Lisp_Object frame; |
| 1521 | { | 1560 | { |
| 1522 | Lisp_Object scan; | ||
| 1523 | Lisp_Object display; | 1561 | Lisp_Object display; |
| 1524 | 1562 | ||
| 1525 | /* FIXME: Code duplication. */ | 1563 | /* FIXME: weird behavior. */ |
| 1526 | 1564 | ||
| 1527 | if (NILP (frame)) | 1565 | if (NILP (frame)) |
| 1528 | { | 1566 | { |
| 1529 | /* Try to find VAR in Vprocess_environment first. */ | 1567 | /* Try to find VAR in Vprocess_environment first. */ |
| 1530 | for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan)) | 1568 | if (getenv_internal_1 (var, varlen, value, valuelen, |
| 1531 | { | 1569 | Vprocess_environment)) |
| 1532 | Lisp_Object entry = XCAR (scan); | 1570 | return value ? 1 : 0; |
| 1533 | if (STRINGP (entry) | 1571 | else |
| 1534 | && SBYTES (entry) >= varlen | 1572 | frame = selected_frame; |
| 1535 | #ifdef WINDOWSNT | ||
| 1536 | /* NT environment variables are case insensitive. */ | ||
| 1537 | && ! strnicmp (SDATA (entry), var, varlen) | ||
| 1538 | #else /* not WINDOWSNT */ | ||
| 1539 | && ! bcmp (SDATA (entry), var, varlen) | ||
| 1540 | #endif /* not WINDOWSNT */ | ||
| 1541 | ) | ||
| 1542 | { | ||
| 1543 | if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=') | ||
| 1544 | { | ||
| 1545 | *value = (char *) SDATA (entry) + (varlen + 1); | ||
| 1546 | *valuelen = SBYTES (entry) - (varlen + 1); | ||
| 1547 | return 1; | ||
| 1548 | } | ||
| 1549 | else if (SBYTES (entry) == varlen) | ||
| 1550 | { | ||
| 1551 | /* Lone variable names in Vprocess_environment mean that | ||
| 1552 | variable should be removed from the environment. */ | ||
| 1553 | return 0; | ||
| 1554 | } | ||
| 1555 | } | ||
| 1556 | } | ||
| 1557 | frame = selected_frame; | ||
| 1558 | } | 1573 | } |
| 1559 | 1574 | ||
| 1560 | /* For DISPLAY first try to get the values from the frame. */ | 1575 | /* For DISPLAY first try to get the values from the frame. */ |
| @@ -1567,65 +1582,19 @@ getenv_internal (var, varlen, value, valuelen, frame) | |||
| 1567 | return 1; | 1582 | return 1; |
| 1568 | } | 1583 | } |
| 1569 | 1584 | ||
| 1570 | { | 1585 | /* Try to find VAR in Vprocess_environment. */ |
| 1571 | /* Try to find VAR in Vprocess_environment. */ | 1586 | if (getenv_internal_1 (var, varlen, value, valuelen, |
| 1572 | for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan)) | 1587 | Vprocess_environment)) |
| 1573 | { | 1588 | return value ? 1 : 0; |
| 1574 | Lisp_Object entry = XCAR (scan); | ||
| 1575 | if (STRINGP (entry) | ||
| 1576 | && SBYTES (entry) >= varlen | ||
| 1577 | #ifdef WINDOWSNT | ||
| 1578 | /* NT environment variables are case insensitive. */ | ||
| 1579 | && ! strnicmp (SDATA (entry), var, varlen) | ||
| 1580 | #else /* not WINDOWSNT */ | ||
| 1581 | && ! bcmp (SDATA (entry), var, varlen) | ||
| 1582 | #endif /* not WINDOWSNT */ | ||
| 1583 | ) | ||
| 1584 | { | ||
| 1585 | if (SBYTES (entry) > varlen && SREF (entry, varlen) == '=') | ||
| 1586 | { | ||
| 1587 | *value = (char *) SDATA (entry) + (varlen + 1); | ||
| 1588 | *valuelen = SBYTES (entry) - (varlen + 1); | ||
| 1589 | return 1; | ||
| 1590 | } | ||
| 1591 | else if (SBYTES (entry) == varlen) | ||
| 1592 | { | ||
| 1593 | /* Lone variable names in Vprocess_environment mean that | ||
| 1594 | variable should be removed from the environment. */ | ||
| 1595 | return 0; | ||
| 1596 | } | ||
| 1597 | } | ||
| 1598 | } | ||
| 1599 | } | ||
| 1600 | 1589 | ||
| 1601 | #if 0 | 1590 | #if 0 |
| 1602 | /* Find the environment in which to search the variable. */ | 1591 | /* Find the environment in which to search the variable. */ |
| 1603 | CHECK_FRAME (frame); | 1592 | CHECK_FRAME (frame); |
| 1604 | frame = Fframe_with_environment (frame); | 1593 | frame = Fframe_with_environment (frame); |
| 1605 | 1594 | ||
| 1606 | for (scan = get_frame_param (XFRAME (frame), Qenvironment); | 1595 | if (getenv_internal_1 (var, varlen, value, valuelen, |
| 1607 | CONSP (scan); | 1596 | get_frame_param (XFRAME (frame), Qenvironment))) |
| 1608 | scan = XCDR (scan)) | 1597 | return value ? 1 : 0; |
| 1609 | { | ||
| 1610 | Lisp_Object entry; | ||
| 1611 | |||
| 1612 | entry = XCAR (scan); | ||
| 1613 | if (STRINGP (entry) | ||
| 1614 | && SBYTES (entry) > varlen | ||
| 1615 | && SREF (entry, varlen) == '=' | ||
| 1616 | #ifdef WINDOWSNT | ||
| 1617 | /* NT environment variables are case insensitive. */ | ||
| 1618 | && ! strnicmp (SDATA (entry), var, varlen) | ||
| 1619 | #else /* not WINDOWSNT */ | ||
| 1620 | && ! bcmp (SDATA (entry), var, varlen) | ||
| 1621 | #endif /* not WINDOWSNT */ | ||
| 1622 | ) | ||
| 1623 | { | ||
| 1624 | *value = (char *) SDATA (entry) + (varlen + 1); | ||
| 1625 | *valuelen = SBYTES (entry) - (varlen + 1); | ||
| 1626 | return 1; | ||
| 1627 | } | ||
| 1628 | } | ||
| 1629 | #endif | 1598 | #endif |
| 1630 | return 0; | 1599 | return 0; |
| 1631 | } | 1600 | } |
| @@ -1639,18 +1608,28 @@ This function searches `process-environment' for VARIABLE. If it is | |||
| 1639 | not found there, then it continues the search in the environment list | 1608 | not found there, then it continues the search in the environment list |
| 1640 | of the selected frame. | 1609 | of the selected frame. |
| 1641 | 1610 | ||
| 1642 | If optional parameter FRAME is non-nil, then this function will ignore | 1611 | If optional parameter ENV is a list, then search this list instead of |
| 1643 | `process-environment' and will simply look up the variable in that | 1612 | `process-environment', and return t when encountering a negative entry. |
| 1644 | frame's environment. */) | 1613 | |
| 1645 | (variable, frame) | 1614 | If it is a frame, then this function will ignore `process-environment' and |
| 1646 | Lisp_Object variable, frame; | 1615 | will simply look up the variable in that frame's environment. */) |
| 1616 | (variable, env) | ||
| 1617 | Lisp_Object variable, env; | ||
| 1647 | { | 1618 | { |
| 1648 | char *value; | 1619 | char *value; |
| 1649 | int valuelen; | 1620 | int valuelen; |
| 1650 | 1621 | ||
| 1651 | CHECK_STRING (variable); | 1622 | CHECK_STRING (variable); |
| 1652 | if (getenv_internal (SDATA (variable), SBYTES (variable), | 1623 | if (CONSP (env)) |
| 1653 | &value, &valuelen, frame)) | 1624 | { |
| 1625 | if (getenv_internal_1 (SDATA (variable), SBYTES (variable), | ||
| 1626 | &value, &valuelen, env)) | ||
| 1627 | return value ? make_string (value, valuelen) : Qt; | ||
| 1628 | else | ||
| 1629 | return Qnil; | ||
| 1630 | } | ||
| 1631 | else if (getenv_internal (SDATA (variable), SBYTES (variable), | ||
| 1632 | &value, &valuelen, env)) | ||
| 1654 | return make_string (value, valuelen); | 1633 | return make_string (value, valuelen); |
| 1655 | else | 1634 | else |
| 1656 | return Qnil; | 1635 | return Qnil; |