expand.c (223010) | expand.c (223024) |
---|---|
1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1997-2005 5 * Herbert Xu <herbert@gondor.apana.org.au>. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Kenneth Almquist. --- 24 unchanged lines hidden (view full) --- 33 */ 34 35#ifndef lint 36#if 0 37static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; 38#endif 39#endif /* not lint */ 40#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1997-2005 5 * Herbert Xu <herbert@gondor.apana.org.au>. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Kenneth Almquist. --- 24 unchanged lines hidden (view full) --- 33 */ 34 35#ifndef lint 36#if 0 37static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; 38#endif 39#endif /* not lint */ 40#include <sys/cdefs.h> |
41__FBSDID("$FreeBSD: head/bin/sh/expand.c 223010 2011-06-12 12:54:52Z jilles $"); | 41__FBSDID("$FreeBSD: head/bin/sh/expand.c 223024 2011-06-12 23:06:04Z jilles $"); |
42 43#include <sys/types.h> 44#include <sys/time.h> 45#include <sys/stat.h> 46#include <dirent.h> 47#include <errno.h> 48#include <inttypes.h> 49#include <limits.h> --- 1566 unchanged lines hidden (view full) --- 1616 if (neg) 1617 *--p = '-'; 1618 1619 STPUTS(p, buf); 1620 return buf; 1621} 1622 1623/* | 42 43#include <sys/types.h> 44#include <sys/time.h> 45#include <sys/stat.h> 46#include <dirent.h> 47#include <errno.h> 48#include <inttypes.h> 49#include <limits.h> --- 1566 unchanged lines hidden (view full) --- 1616 if (neg) 1617 *--p = '-'; 1618 1619 STPUTS(p, buf); 1620 return buf; 1621} 1622 1623/* |
1624 * Check statically if expanding a string may have side effects. 1625 */ 1626int 1627expandhassideeffects(const char *p) 1628{ 1629 int c; 1630 int arinest; 1631 1632 arinest = 0; 1633 while ((c = *p++) != '\0') { 1634 switch (c) { 1635 case CTLESC: 1636 p++; 1637 break; 1638 case CTLVAR: 1639 c = *p++; 1640 /* Expanding $! sets the job to remembered. */ 1641 if (*p == '!') 1642 return 1; 1643 if ((c & VSTYPE) == VSASSIGN) 1644 return 1; 1645 /* 1646 * If we are in arithmetic, the parameter may contain 1647 * '=' which may cause side effects. Exceptions are 1648 * the length of a parameter and $$, $# and $? which 1649 * are always numeric. 1650 */ 1651 if ((c & VSTYPE) == VSLENGTH) { 1652 while (*p != '=') 1653 p++; 1654 p++; 1655 break; 1656 } 1657 if ((*p == '$' || *p == '#' || *p == '?') && 1658 p[1] == '=') { 1659 p += 2; 1660 break; 1661 } 1662 if (arinest > 0) 1663 return 1; 1664 break; 1665 case CTLBACKQ: 1666 case CTLBACKQ | CTLQUOTE: 1667 if (arinest > 0) 1668 return 1; 1669 break; 1670 case CTLARI: 1671 arinest++; 1672 break; 1673 case CTLENDARI: 1674 arinest--; 1675 break; 1676 case '=': 1677 if (*p == '=') { 1678 /* Allow '==' operator. */ 1679 p++; 1680 continue; 1681 } 1682 if (arinest > 0) 1683 return 1; 1684 break; 1685 case '!': case '<': case '>': 1686 /* Allow '!=', '<=', '>=' operators. */ 1687 if (*p == '=') 1688 p++; 1689 break; 1690 } 1691 } 1692 return 0; 1693} 1694 1695/* | |
1696 * Do most of the work for wordexp(3). 1697 */ 1698 1699int 1700wordexpcmd(int argc, char **argv) 1701{ 1702 size_t len; 1703 int i; 1704 1705 out1fmt("%08x", argc - 1); 1706 for (i = 1, len = 0; i < argc; i++) 1707 len += strlen(argv[i]); 1708 out1fmt("%08x", (int)len); 1709 for (i = 1; i < argc; i++) 1710 outbin(argv[i], strlen(argv[i]) + 1, out1); 1711 return (0); 1712} | 1624 * Do most of the work for wordexp(3). 1625 */ 1626 1627int 1628wordexpcmd(int argc, char **argv) 1629{ 1630 size_t len; 1631 int i; 1632 1633 out1fmt("%08x", argc - 1); 1634 for (i = 1, len = 0; i < argc; i++) 1635 len += strlen(argv[i]); 1636 out1fmt("%08x", (int)len); 1637 for (i = 1; i < argc; i++) 1638 outbin(argv[i], strlen(argv[i]) + 1, out1); 1639 return (0); 1640} |