Mercurial > emacs
comparison src/fileio.c @ 40168:a35ceaf34f12
Remove unused code.
author | Pavel Janík <Pavel@Janik.cz> |
---|---|
date | Mon, 22 Oct 2001 06:26:10 +0000 |
parents | e2feb0871205 |
children | f4cf12231193 |
comparison
equal
deleted
inserted
replaced
40167:2a6c5da21581 | 40168:a35ceaf34f12 |
---|---|
1645 #endif /* DOS_NT */ | 1645 #endif /* DOS_NT */ |
1646 | 1646 |
1647 return make_string (target, o - target); | 1647 return make_string (target, o - target); |
1648 } | 1648 } |
1649 | 1649 |
1650 #if 0 | |
1651 /* Changed this DEFUN to a DEAFUN, so as not to confuse `make-docfile'. */ | |
1652 DEAFUN ("expand-file-name", Fexpand_file_name, Sexpand_file_name, 1, 2, 0, | |
1653 "Convert FILENAME to absolute, and canonicalize it.\n\ | |
1654 Second arg DEFAULT is directory to start with if FILENAME is relative\n\ | |
1655 (does not start with slash); if DEFAULT is nil or missing,\n\ | |
1656 the current buffer's value of default-directory is used.\n\ | |
1657 Filenames containing `.' or `..' as components are simplified;\n\ | |
1658 initial `~/' expands to your home directory.\n\ | |
1659 See also the function `substitute-in-file-name'.") | |
1660 (name, defalt) | |
1661 Lisp_Object name, defalt; | |
1662 { | |
1663 unsigned char *nm; | |
1664 | |
1665 register unsigned char *newdir, *p, *o; | |
1666 int tlen; | |
1667 unsigned char *target; | |
1668 struct passwd *pw; | |
1669 int lose; | |
1670 #ifdef VMS | |
1671 unsigned char * colon = 0; | |
1672 unsigned char * close = 0; | |
1673 unsigned char * slash = 0; | |
1674 unsigned char * brack = 0; | |
1675 int lbrack = 0, rbrack = 0; | |
1676 int dots = 0; | |
1677 #endif /* VMS */ | |
1678 | |
1679 CHECK_STRING (name, 0); | |
1680 | |
1681 #ifdef VMS | |
1682 /* Filenames on VMS are always upper case. */ | |
1683 name = Fupcase (name); | |
1684 #endif | |
1685 | |
1686 nm = XSTRING (name)->data; | |
1687 | |
1688 /* If nm is absolute, flush ...// and detect /./ and /../. | |
1689 If no /./ or /../ we can return right away. */ | |
1690 if ( | |
1691 nm[0] == '/' | |
1692 #ifdef VMS | |
1693 || index (nm, ':') | |
1694 #endif /* VMS */ | |
1695 ) | |
1696 { | |
1697 p = nm; | |
1698 lose = 0; | |
1699 while (*p) | |
1700 { | |
1701 if (p[0] == '/' && p[1] == '/' | |
1702 #ifdef APOLLO | |
1703 /* // at start of filename is meaningful on Apollo system. */ | |
1704 && nm != p | |
1705 #endif /* APOLLO */ | |
1706 ) | |
1707 nm = p + 1; | |
1708 if (p[0] == '/' && p[1] == '~') | |
1709 nm = p + 1, lose = 1; | |
1710 if (p[0] == '/' && p[1] == '.' | |
1711 && (p[2] == '/' || p[2] == 0 | |
1712 || (p[2] == '.' && (p[3] == '/' || p[3] == 0)))) | |
1713 lose = 1; | |
1714 #ifdef VMS | |
1715 if (p[0] == '\\') | |
1716 lose = 1; | |
1717 if (p[0] == '/') { | |
1718 /* if dev:[dir]/, move nm to / */ | |
1719 if (!slash && p > nm && (brack || colon)) { | |
1720 nm = (brack ? brack + 1 : colon + 1); | |
1721 lbrack = rbrack = 0; | |
1722 brack = 0; | |
1723 colon = 0; | |
1724 } | |
1725 slash = p; | |
1726 } | |
1727 if (p[0] == '-') | |
1728 #ifndef VMS4_4 | |
1729 /* VMS pre V4.4,convert '-'s in filenames. */ | |
1730 if (lbrack == rbrack) | |
1731 { | |
1732 if (dots < 2) /* this is to allow negative version numbers */ | |
1733 p[0] = '_'; | |
1734 } | |
1735 else | |
1736 #endif /* VMS4_4 */ | |
1737 if (lbrack > rbrack && | |
1738 ((p[-1] == '.' || p[-1] == '[' || p[-1] == '<') && | |
1739 (p[1] == '.' || p[1] == ']' || p[1] == '>'))) | |
1740 lose = 1; | |
1741 #ifndef VMS4_4 | |
1742 else | |
1743 p[0] = '_'; | |
1744 #endif /* VMS4_4 */ | |
1745 /* count open brackets, reset close bracket pointer */ | |
1746 if (p[0] == '[' || p[0] == '<') | |
1747 lbrack++, brack = 0; | |
1748 /* count close brackets, set close bracket pointer */ | |
1749 if (p[0] == ']' || p[0] == '>') | |
1750 rbrack++, brack = p; | |
1751 /* detect ][ or >< */ | |
1752 if ((p[0] == ']' || p[0] == '>') && (p[1] == '[' || p[1] == '<')) | |
1753 lose = 1; | |
1754 if ((p[0] == ':' || p[0] == ']' || p[0] == '>') && p[1] == '~') | |
1755 nm = p + 1, lose = 1; | |
1756 if (p[0] == ':' && (colon || slash)) | |
1757 /* if dev1:[dir]dev2:, move nm to dev2: */ | |
1758 if (brack) | |
1759 { | |
1760 nm = brack + 1; | |
1761 brack = 0; | |
1762 } | |
1763 /* If /name/dev:, move nm to dev: */ | |
1764 else if (slash) | |
1765 nm = slash + 1; | |
1766 /* If node::dev:, move colon following dev */ | |
1767 else if (colon && colon[-1] == ':') | |
1768 colon = p; | |
1769 /* If dev1:dev2:, move nm to dev2: */ | |
1770 else if (colon && colon[-1] != ':') | |
1771 { | |
1772 nm = colon + 1; | |
1773 colon = 0; | |
1774 } | |
1775 if (p[0] == ':' && !colon) | |
1776 { | |
1777 if (p[1] == ':') | |
1778 p++; | |
1779 colon = p; | |
1780 } | |
1781 if (lbrack == rbrack) | |
1782 if (p[0] == ';') | |
1783 dots = 2; | |
1784 else if (p[0] == '.') | |
1785 dots++; | |
1786 #endif /* VMS */ | |
1787 p++; | |
1788 } | |
1789 if (!lose) | |
1790 { | |
1791 #ifdef VMS | |
1792 if (index (nm, '/')) | |
1793 return build_string (sys_translate_unix (nm)); | |
1794 #endif /* VMS */ | |
1795 if (nm == XSTRING (name)->data) | |
1796 return name; | |
1797 return build_string (nm); | |
1798 } | |
1799 } | |
1800 | |
1801 /* Now determine directory to start with and put it in NEWDIR */ | |
1802 | |
1803 newdir = 0; | |
1804 | |
1805 if (nm[0] == '~') /* prefix ~ */ | |
1806 if (nm[1] == '/' | |
1807 #ifdef VMS | |
1808 || nm[1] == ':' | |
1809 #endif /* VMS */ | |
1810 || nm[1] == 0)/* ~/filename */ | |
1811 { | |
1812 if (!(newdir = (unsigned char *) egetenv ("HOME"))) | |
1813 newdir = (unsigned char *) ""; | |
1814 nm++; | |
1815 #ifdef VMS | |
1816 nm++; /* Don't leave the slash in nm. */ | |
1817 #endif /* VMS */ | |
1818 } | |
1819 else /* ~user/filename */ | |
1820 { | |
1821 /* Get past ~ to user */ | |
1822 unsigned char *user = nm + 1; | |
1823 /* Find end of name. */ | |
1824 unsigned char *ptr = (unsigned char *) index (user, '/'); | |
1825 int len = ptr ? ptr - user : strlen (user); | |
1826 #ifdef VMS | |
1827 unsigned char *ptr1 = index (user, ':'); | |
1828 if (ptr1 != 0 && ptr1 - user < len) | |
1829 len = ptr1 - user; | |
1830 #endif /* VMS */ | |
1831 /* Copy the user name into temp storage. */ | |
1832 o = (unsigned char *) alloca (len + 1); | |
1833 bcopy ((char *) user, o, len); | |
1834 o[len] = 0; | |
1835 | |
1836 /* Look up the user name. */ | |
1837 pw = (struct passwd *) getpwnam (o + 1); | |
1838 if (!pw) | |
1839 error ("\"%s\" isn't a registered user", o + 1); | |
1840 | |
1841 newdir = (unsigned char *) pw->pw_dir; | |
1842 | |
1843 /* Discard the user name from NM. */ | |
1844 nm += len; | |
1845 } | |
1846 | |
1847 if (nm[0] != '/' | |
1848 #ifdef VMS | |
1849 && !index (nm, ':') | |
1850 #endif /* not VMS */ | |
1851 && !newdir) | |
1852 { | |
1853 if (NILP (defalt)) | |
1854 defalt = current_buffer->directory; | |
1855 CHECK_STRING (defalt, 1); | |
1856 newdir = XSTRING (defalt)->data; | |
1857 } | |
1858 | |
1859 /* Now concatenate the directory and name to new space in the stack frame */ | |
1860 | |
1861 tlen = (newdir ? strlen (newdir) + 1 : 0) + strlen (nm) + 1; | |
1862 target = (unsigned char *) alloca (tlen); | |
1863 *target = 0; | |
1864 | |
1865 if (newdir) | |
1866 { | |
1867 #ifndef VMS | |
1868 if (nm[0] == 0 || nm[0] == '/') | |
1869 strcpy (target, newdir); | |
1870 else | |
1871 #endif | |
1872 file_name_as_directory (target, newdir); | |
1873 } | |
1874 | |
1875 strcat (target, nm); | |
1876 #ifdef VMS | |
1877 if (index (target, '/')) | |
1878 strcpy (target, sys_translate_unix (target)); | |
1879 #endif /* VMS */ | |
1880 | |
1881 /* Now canonicalize by removing /. and /foo/.. if they appear */ | |
1882 | |
1883 p = target; | |
1884 o = target; | |
1885 | |
1886 while (*p) | |
1887 { | |
1888 #ifdef VMS | |
1889 if (*p != ']' && *p != '>' && *p != '-') | |
1890 { | |
1891 if (*p == '\\') | |
1892 p++; | |
1893 *o++ = *p++; | |
1894 } | |
1895 else if ((p[0] == ']' || p[0] == '>') && p[0] == p[1] + 2) | |
1896 /* brackets are offset from each other by 2 */ | |
1897 { | |
1898 p += 2; | |
1899 if (*p != '.' && *p != '-' && o[-1] != '.') | |
1900 /* convert [foo][bar] to [bar] */ | |
1901 while (o[-1] != '[' && o[-1] != '<') | |
1902 o--; | |
1903 else if (*p == '-' && *o != '.') | |
1904 *--p = '.'; | |
1905 } | |
1906 else if (p[0] == '-' && o[-1] == '.' && | |
1907 (p[1] == '.' || p[1] == ']' || p[1] == '>')) | |
1908 /* flush .foo.- ; leave - if stopped by '[' or '<' */ | |
1909 { | |
1910 do | |
1911 o--; | |
1912 while (o[-1] != '.' && o[-1] != '[' && o[-1] != '<'); | |
1913 if (p[1] == '.') /* foo.-.bar ==> bar. */ | |
1914 p += 2; | |
1915 else if (o[-1] == '.') /* '.foo.-]' ==> ']' */ | |
1916 p++, o--; | |
1917 /* else [foo.-] ==> [-] */ | |
1918 } | |
1919 else | |
1920 { | |
1921 #ifndef VMS4_4 | |
1922 if (*p == '-' && | |
1923 o[-1] != '[' && o[-1] != '<' && o[-1] != '.' && | |
1924 p[1] != ']' && p[1] != '>' && p[1] != '.') | |
1925 *p = '_'; | |
1926 #endif /* VMS4_4 */ | |
1927 *o++ = *p++; | |
1928 } | |
1929 #else /* not VMS */ | |
1930 if (*p != '/') | |
1931 { | |
1932 *o++ = *p++; | |
1933 } | |
1934 else if (!strncmp (p, "//", 2) | |
1935 #ifdef APOLLO | |
1936 /* // at start of filename is meaningful in Apollo system. */ | |
1937 && o != target | |
1938 #endif /* APOLLO */ | |
1939 ) | |
1940 { | |
1941 o = target; | |
1942 p++; | |
1943 } | |
1944 else if (p[0] == '/' && p[1] == '.' && | |
1945 (p[2] == '/' || p[2] == 0)) | |
1946 p += 2; | |
1947 else if (!strncmp (p, "/..", 3) | |
1948 /* `/../' is the "superroot" on certain file systems. */ | |
1949 && o != target | |
1950 && (p[3] == '/' || p[3] == 0)) | |
1951 { | |
1952 while (o != target && *--o != '/') | |
1953 ; | |
1954 #ifdef APOLLO | |
1955 if (o == target + 1 && o[-1] == '/' && o[0] == '/') | |
1956 ++o; | |
1957 else | |
1958 #endif /* APOLLO */ | |
1959 if (o == target && *o == '/') | |
1960 ++o; | |
1961 p += 3; | |
1962 } | |
1963 else | |
1964 { | |
1965 *o++ = *p++; | |
1966 } | |
1967 #endif /* not VMS */ | |
1968 } | |
1969 | |
1970 return make_string (target, o - target); | |
1971 } | |
1972 #endif | |
1973 | 1650 |
1974 DEFUN ("substitute-in-file-name", Fsubstitute_in_file_name, | 1651 DEFUN ("substitute-in-file-name", Fsubstitute_in_file_name, |
1975 Ssubstitute_in_file_name, 1, 1, 0, | 1652 Ssubstitute_in_file_name, 1, 1, 0, |
1976 doc: /* Substitute environment variables referred to in FILENAME. | 1653 doc: /* Substitute environment variables referred to in FILENAME. |
1977 `$FOO' where FOO is an environment variable name means to substitute | 1654 `$FOO' where FOO is an environment variable name means to substitute |