diff options
| author | Lars Ingebrigtsen | 2018-04-14 21:55:39 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2018-04-14 21:55:39 +0200 |
| commit | 56c4ce266d395a5940576bea3e69b636fb549b1e (patch) | |
| tree | a7741f819e7c514f148bea473ffd27d25f2b75ea /src | |
| parent | f939cd025539791ad9af34b43af029a4f3d04f5f (diff) | |
| download | emacs-56c4ce266d395a5940576bea3e69b636fb549b1e.tar.gz emacs-56c4ce266d395a5940576bea3e69b636fb549b1e.zip | |
Indent after transforming for loop into do/while
Diffstat (limited to 'src')
| -rw-r--r-- | src/lread.c | 353 |
1 files changed, 176 insertions, 177 deletions
diff --git a/src/lread.c b/src/lread.c index 8019443c09f..5fe4d26fd94 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -1587,192 +1587,191 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, | |||
| 1587 | 1587 | ||
| 1588 | absolute = complete_filename_p (str); | 1588 | absolute = complete_filename_p (str); |
| 1589 | 1589 | ||
| 1590 | do | 1590 | do { |
| 1591 | { | 1591 | ptrdiff_t baselen, prefixlen; |
| 1592 | ptrdiff_t baselen, prefixlen; | 1592 | |
| 1593 | 1593 | if (NILP (path)) | |
| 1594 | if (NILP (path)) | 1594 | filename = str; |
| 1595 | filename = str; | 1595 | else |
| 1596 | else | 1596 | filename = Fexpand_file_name (str, XCAR (path)); |
| 1597 | filename = Fexpand_file_name (str, XCAR (path)); | 1597 | if (!complete_filename_p (filename)) |
| 1598 | if (!complete_filename_p (filename)) | 1598 | /* If there are non-absolute elts in PATH (eg "."). */ |
| 1599 | /* If there are non-absolute elts in PATH (eg "."). */ | 1599 | /* Of course, this could conceivably lose if luser sets |
| 1600 | /* Of course, this could conceivably lose if luser sets | 1600 | default-directory to be something non-absolute... */ |
| 1601 | default-directory to be something non-absolute... */ | 1601 | { |
| 1602 | { | 1602 | filename = Fexpand_file_name (filename, BVAR (current_buffer, directory)); |
| 1603 | filename = Fexpand_file_name (filename, BVAR (current_buffer, directory)); | 1603 | if (!complete_filename_p (filename)) |
| 1604 | if (!complete_filename_p (filename)) | 1604 | /* Give up on this path element! */ |
| 1605 | /* Give up on this path element! */ | 1605 | continue; |
| 1606 | continue; | 1606 | } |
| 1607 | } | ||
| 1608 | 1607 | ||
| 1609 | /* Calculate maximum length of any filename made from | 1608 | /* Calculate maximum length of any filename made from |
| 1610 | this path element/specified file name and any possible suffix. */ | 1609 | this path element/specified file name and any possible suffix. */ |
| 1611 | want_length = max_suffix_len + SBYTES (filename); | 1610 | want_length = max_suffix_len + SBYTES (filename); |
| 1612 | if (fn_size <= want_length) | 1611 | if (fn_size <= want_length) |
| 1613 | { | 1612 | { |
| 1614 | fn_size = 100 + want_length; | 1613 | fn_size = 100 + want_length; |
| 1615 | fn = SAFE_ALLOCA (fn_size); | 1614 | fn = SAFE_ALLOCA (fn_size); |
| 1616 | } | 1615 | } |
| 1617 | 1616 | ||
| 1618 | /* Copy FILENAME's data to FN but remove starting /: if any. */ | 1617 | /* Copy FILENAME's data to FN but remove starting /: if any. */ |
| 1619 | prefixlen = ((SCHARS (filename) > 2 | 1618 | prefixlen = ((SCHARS (filename) > 2 |
| 1620 | && SREF (filename, 0) == '/' | 1619 | && SREF (filename, 0) == '/' |
| 1621 | && SREF (filename, 1) == ':') | 1620 | && SREF (filename, 1) == ':') |
| 1622 | ? 2 : 0); | 1621 | ? 2 : 0); |
| 1623 | baselen = SBYTES (filename) - prefixlen; | 1622 | baselen = SBYTES (filename) - prefixlen; |
| 1624 | memcpy (fn, SDATA (filename) + prefixlen, baselen); | 1623 | memcpy (fn, SDATA (filename) + prefixlen, baselen); |
| 1625 | 1624 | ||
| 1626 | /* Loop over suffixes. */ | 1625 | /* Loop over suffixes. */ |
| 1627 | for (tail = NILP (suffixes) ? list1 (empty_unibyte_string) : suffixes; | 1626 | for (tail = NILP (suffixes) ? list1 (empty_unibyte_string) : suffixes; |
| 1628 | CONSP (tail); tail = XCDR (tail)) | 1627 | CONSP (tail); tail = XCDR (tail)) |
| 1629 | { | 1628 | { |
| 1630 | Lisp_Object suffix = XCAR (tail); | 1629 | Lisp_Object suffix = XCAR (tail); |
| 1631 | ptrdiff_t fnlen, lsuffix = SBYTES (suffix); | 1630 | ptrdiff_t fnlen, lsuffix = SBYTES (suffix); |
| 1632 | Lisp_Object handler; | 1631 | Lisp_Object handler; |
| 1633 | 1632 | ||
| 1634 | /* Make complete filename by appending SUFFIX. */ | 1633 | /* Make complete filename by appending SUFFIX. */ |
| 1635 | memcpy (fn + baselen, SDATA (suffix), lsuffix + 1); | 1634 | memcpy (fn + baselen, SDATA (suffix), lsuffix + 1); |
| 1636 | fnlen = baselen + lsuffix; | 1635 | fnlen = baselen + lsuffix; |
| 1637 | 1636 | ||
| 1638 | /* Check that the file exists and is not a directory. */ | 1637 | /* Check that the file exists and is not a directory. */ |
| 1639 | /* We used to only check for handlers on non-absolute file names: | 1638 | /* We used to only check for handlers on non-absolute file names: |
| 1640 | if (absolute) | 1639 | if (absolute) |
| 1641 | handler = Qnil; | 1640 | handler = Qnil; |
| 1642 | else | 1641 | else |
| 1643 | handler = Ffind_file_name_handler (filename, Qfile_exists_p); | 1642 | handler = Ffind_file_name_handler (filename, Qfile_exists_p); |
| 1644 | It's not clear why that was the case and it breaks things like | 1643 | It's not clear why that was the case and it breaks things like |
| 1645 | (load "/bar.el") where the file is actually "/bar.el.gz". */ | 1644 | (load "/bar.el") where the file is actually "/bar.el.gz". */ |
| 1646 | /* make_string has its own ideas on when to return a unibyte | 1645 | /* make_string has its own ideas on when to return a unibyte |
| 1647 | string and when a multibyte string, but we know better. | 1646 | string and when a multibyte string, but we know better. |
| 1648 | We must have a unibyte string when dumping, since | 1647 | We must have a unibyte string when dumping, since |
| 1649 | file-name encoding is shaky at best at that time, and in | 1648 | file-name encoding is shaky at best at that time, and in |
| 1650 | particular default-file-name-coding-system is reset | 1649 | particular default-file-name-coding-system is reset |
| 1651 | several times during loadup. We therefore don't want to | 1650 | several times during loadup. We therefore don't want to |
| 1652 | encode the file before passing it to file I/O library | 1651 | encode the file before passing it to file I/O library |
| 1653 | functions. */ | 1652 | functions. */ |
| 1654 | if (!STRING_MULTIBYTE (filename) && !STRING_MULTIBYTE (suffix)) | 1653 | if (!STRING_MULTIBYTE (filename) && !STRING_MULTIBYTE (suffix)) |
| 1655 | string = make_unibyte_string (fn, fnlen); | 1654 | string = make_unibyte_string (fn, fnlen); |
| 1656 | else | 1655 | else |
| 1657 | string = make_string (fn, fnlen); | 1656 | string = make_string (fn, fnlen); |
| 1658 | handler = Ffind_file_name_handler (string, Qfile_exists_p); | 1657 | handler = Ffind_file_name_handler (string, Qfile_exists_p); |
| 1659 | if ((!NILP (handler) || (!NILP (predicate) && !EQ (predicate, Qt))) | 1658 | if ((!NILP (handler) || (!NILP (predicate) && !EQ (predicate, Qt))) |
| 1660 | && !NATNUMP (predicate)) | 1659 | && !NATNUMP (predicate)) |
| 1661 | { | 1660 | { |
| 1662 | bool exists; | 1661 | bool exists; |
| 1663 | if (NILP (predicate) || EQ (predicate, Qt)) | 1662 | if (NILP (predicate) || EQ (predicate, Qt)) |
| 1664 | exists = !NILP (Ffile_readable_p (string)); | 1663 | exists = !NILP (Ffile_readable_p (string)); |
| 1665 | else | 1664 | else |
| 1666 | { | 1665 | { |
| 1667 | Lisp_Object tmp = call1 (predicate, string); | 1666 | Lisp_Object tmp = call1 (predicate, string); |
| 1668 | if (NILP (tmp)) | 1667 | if (NILP (tmp)) |
| 1668 | exists = false; | ||
| 1669 | else if (EQ (tmp, Qdir_ok) | ||
| 1670 | || NILP (Ffile_directory_p (string))) | ||
| 1671 | exists = true; | ||
| 1672 | else | ||
| 1673 | { | ||
| 1669 | exists = false; | 1674 | exists = false; |
| 1670 | else if (EQ (tmp, Qdir_ok) | 1675 | last_errno = EISDIR; |
| 1671 | || NILP (Ffile_directory_p (string))) | 1676 | } |
| 1672 | exists = true; | 1677 | } |
| 1673 | else | ||
| 1674 | { | ||
| 1675 | exists = false; | ||
| 1676 | last_errno = EISDIR; | ||
| 1677 | } | ||
| 1678 | } | ||
| 1679 | 1678 | ||
| 1680 | if (exists) | 1679 | if (exists) |
| 1681 | { | 1680 | { |
| 1682 | /* We succeeded; return this descriptor and filename. */ | 1681 | /* We succeeded; return this descriptor and filename. */ |
| 1683 | if (storeptr) | 1682 | if (storeptr) |
| 1684 | *storeptr = string; | 1683 | *storeptr = string; |
| 1685 | SAFE_FREE (); | 1684 | SAFE_FREE (); |
| 1686 | return -2; | 1685 | return -2; |
| 1687 | } | 1686 | } |
| 1688 | } | 1687 | } |
| 1689 | else | 1688 | else |
| 1690 | { | 1689 | { |
| 1691 | int fd; | 1690 | int fd; |
| 1692 | const char *pfn; | 1691 | const char *pfn; |
| 1693 | struct stat st; | 1692 | struct stat st; |
| 1694 | 1693 | ||
| 1695 | encoded_fn = ENCODE_FILE (string); | 1694 | encoded_fn = ENCODE_FILE (string); |
| 1696 | pfn = SSDATA (encoded_fn); | 1695 | pfn = SSDATA (encoded_fn); |
| 1697 | 1696 | ||
| 1698 | /* Check that we can access or open it. */ | 1697 | /* Check that we can access or open it. */ |
| 1699 | if (NATNUMP (predicate)) | 1698 | if (NATNUMP (predicate)) |
| 1700 | { | 1699 | { |
| 1701 | fd = -1; | 1700 | fd = -1; |
| 1702 | if (INT_MAX < XFASTINT (predicate)) | 1701 | if (INT_MAX < XFASTINT (predicate)) |
| 1703 | last_errno = EINVAL; | 1702 | last_errno = EINVAL; |
| 1704 | else if (faccessat (AT_FDCWD, pfn, XFASTINT (predicate), | 1703 | else if (faccessat (AT_FDCWD, pfn, XFASTINT (predicate), |
| 1705 | AT_EACCESS) | 1704 | AT_EACCESS) |
| 1706 | == 0) | 1705 | == 0) |
| 1707 | { | 1706 | { |
| 1708 | if (file_directory_p (encoded_fn)) | 1707 | if (file_directory_p (encoded_fn)) |
| 1709 | last_errno = EISDIR; | 1708 | last_errno = EISDIR; |
| 1710 | else | 1709 | else |
| 1711 | fd = 1; | 1710 | fd = 1; |
| 1712 | } | 1711 | } |
| 1713 | } | 1712 | } |
| 1714 | else | 1713 | else |
| 1715 | { | 1714 | { |
| 1716 | fd = emacs_open (pfn, O_RDONLY, 0); | 1715 | fd = emacs_open (pfn, O_RDONLY, 0); |
| 1717 | if (fd < 0) | 1716 | if (fd < 0) |
| 1718 | { | 1717 | { |
| 1719 | if (errno != ENOENT) | 1718 | if (errno != ENOENT) |
| 1720 | last_errno = errno; | 1719 | last_errno = errno; |
| 1721 | } | 1720 | } |
| 1722 | else | 1721 | else |
| 1723 | { | 1722 | { |
| 1724 | int err = (fstat (fd, &st) != 0 ? errno | 1723 | int err = (fstat (fd, &st) != 0 ? errno |
| 1725 | : S_ISDIR (st.st_mode) ? EISDIR : 0); | 1724 | : S_ISDIR (st.st_mode) ? EISDIR : 0); |
| 1726 | if (err) | 1725 | if (err) |
| 1727 | { | 1726 | { |
| 1728 | last_errno = err; | 1727 | last_errno = err; |
| 1729 | emacs_close (fd); | 1728 | emacs_close (fd); |
| 1730 | fd = -1; | 1729 | fd = -1; |
| 1731 | } | 1730 | } |
| 1732 | } | 1731 | } |
| 1733 | } | 1732 | } |
| 1734 | 1733 | ||
| 1735 | if (fd >= 0) | 1734 | if (fd >= 0) |
| 1736 | { | 1735 | { |
| 1737 | if (newer && !NATNUMP (predicate)) | 1736 | if (newer && !NATNUMP (predicate)) |
| 1738 | { | 1737 | { |
| 1739 | struct timespec mtime = get_stat_mtime (&st); | 1738 | struct timespec mtime = get_stat_mtime (&st); |
| 1740 | 1739 | ||
| 1741 | if (timespec_cmp (mtime, save_mtime) <= 0) | 1740 | if (timespec_cmp (mtime, save_mtime) <= 0) |
| 1742 | emacs_close (fd); | 1741 | emacs_close (fd); |
| 1743 | else | 1742 | else |
| 1744 | { | 1743 | { |
| 1745 | if (0 <= save_fd) | 1744 | if (0 <= save_fd) |
| 1746 | emacs_close (save_fd); | 1745 | emacs_close (save_fd); |
| 1747 | save_fd = fd; | 1746 | save_fd = fd; |
| 1748 | save_mtime = mtime; | 1747 | save_mtime = mtime; |
| 1749 | save_string = string; | 1748 | save_string = string; |
| 1750 | } | 1749 | } |
| 1751 | } | 1750 | } |
| 1752 | else | 1751 | else |
| 1753 | { | 1752 | { |
| 1754 | /* We succeeded; return this descriptor and filename. */ | 1753 | /* We succeeded; return this descriptor and filename. */ |
| 1755 | if (storeptr) | 1754 | if (storeptr) |
| 1756 | *storeptr = string; | 1755 | *storeptr = string; |
| 1757 | SAFE_FREE (); | 1756 | SAFE_FREE (); |
| 1758 | return fd; | 1757 | return fd; |
| 1759 | } | 1758 | } |
| 1760 | } | 1759 | } |
| 1761 | 1760 | ||
| 1762 | /* No more suffixes. Return the newest. */ | 1761 | /* No more suffixes. Return the newest. */ |
| 1763 | if (0 <= save_fd && ! CONSP (XCDR (tail))) | 1762 | if (0 <= save_fd && ! CONSP (XCDR (tail))) |
| 1764 | { | 1763 | { |
| 1765 | if (storeptr) | 1764 | if (storeptr) |
| 1766 | *storeptr = save_string; | 1765 | *storeptr = save_string; |
| 1767 | SAFE_FREE (); | 1766 | SAFE_FREE (); |
| 1768 | return save_fd; | 1767 | return save_fd; |
| 1769 | } | 1768 | } |
| 1770 | } | 1769 | } |
| 1771 | } | 1770 | } |
| 1772 | if (absolute) | 1771 | if (absolute) |
| 1773 | break; | 1772 | break; |
| 1774 | path = XCDR (path); | 1773 | path = XCDR (path); |
| 1775 | } while (CONSP (path)); | 1774 | } while (CONSP (path)); |
| 1776 | 1775 | ||
| 1777 | SAFE_FREE (); | 1776 | SAFE_FREE (); |
| 1778 | errno = last_errno; | 1777 | errno = last_errno; |