aboutsummaryrefslogtreecommitdiffstats
path: root/src/mac.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mac.c')
-rw-r--r--src/mac.c299
1 files changed, 174 insertions, 125 deletions
diff --git a/src/mac.c b/src/mac.c
index 14257fdee94..eaf4f029cf1 100644
--- a/src/mac.c
+++ b/src/mac.c
@@ -1672,37 +1672,7 @@ sys_fopen (const char *name, const char *mode)
1672} 1672}
1673 1673
1674 1674
1675long target_ticks = 0; 1675#include "keyboard.h"
1676
1677#ifdef __MRC__
1678__sigfun alarm_signal_func = (__sigfun) 0;
1679#elif __MWERKS__
1680__signal_func_ptr alarm_signal_func = (__signal_func_ptr) 0;
1681#else /* not __MRC__ and not __MWERKS__ */
1682You lose!!!
1683#endif /* not __MRC__ and not __MWERKS__ */
1684
1685
1686/* These functions simulate SIG_ALRM. The stub for function signal
1687 stores the signal handler function in alarm_signal_func if a
1688 SIG_ALRM is encountered. check_alarm is called in XTread_socket,
1689 which emacs calls periodically. A pending alarm is represented by
1690 a non-zero target_ticks value. check_alarm calls the handler
1691 function pointed to by alarm_signal_func if one has been set up and
1692 an alarm is pending. */
1693
1694void
1695check_alarm ()
1696{
1697 if (target_ticks && TickCount () > target_ticks)
1698 {
1699 target_ticks = 0;
1700 if (alarm_signal_func)
1701 (*alarm_signal_func)(SIGALRM);
1702 }
1703}
1704
1705
1706extern Boolean mac_wait_next_event (EventRecord *, UInt32, Boolean); 1676extern Boolean mac_wait_next_event (EventRecord *, UInt32, Boolean);
1707 1677
1708int 1678int
@@ -1713,25 +1683,17 @@ select (n, rfds, wfds, efds, timeout)
1713 SELECT_TYPE *efds; 1683 SELECT_TYPE *efds;
1714 struct timeval *timeout; 1684 struct timeval *timeout;
1715{ 1685{
1716#if TARGET_API_MAC_CARBON
1717 OSErr err; 1686 OSErr err;
1687#if TARGET_API_MAC_CARBON
1718 EventTimeout timeout_sec = 1688 EventTimeout timeout_sec =
1719 (timeout 1689 (timeout
1720 ? (EMACS_SECS (*timeout) * kEventDurationSecond 1690 ? (EMACS_SECS (*timeout) * kEventDurationSecond
1721 + EMACS_USECS (*timeout) * kEventDurationMicrosecond) 1691 + EMACS_USECS (*timeout) * kEventDurationMicrosecond)
1722 : kEventDurationForever); 1692 : kEventDurationForever);
1723 1693
1724 if (FD_ISSET (0, rfds)) 1694 BLOCK_INPUT;
1725 { 1695 err = ReceiveNextEvent (0, NULL, timeout_sec, kEventLeaveInQueue, NULL);
1726 BLOCK_INPUT; 1696 UNBLOCK_INPUT;
1727 err = ReceiveNextEvent (0, NULL, timeout_sec, kEventLeaveInQueue, NULL);
1728 UNBLOCK_INPUT;
1729 if (err == noErr)
1730 return 1;
1731 else
1732 FD_ZERO (rfds);
1733 }
1734 return 0;
1735#else /* not TARGET_API_MAC_CARBON */ 1697#else /* not TARGET_API_MAC_CARBON */
1736 EventRecord e; 1698 EventRecord e;
1737 UInt32 sleep_time = EMACS_SECS (*timeout) * 60 + 1699 UInt32 sleep_time = EMACS_SECS (*timeout) * 60 +
@@ -1746,47 +1708,62 @@ select (n, rfds, wfds, efds, timeout)
1746 read_avail_input which in turn calls XTread_socket to poll for 1708 read_avail_input which in turn calls XTread_socket to poll for
1747 these events. Otherwise these never get processed except but a 1709 these events. Otherwise these never get processed except but a
1748 very slow poll timer. */ 1710 very slow poll timer. */
1749 if (FD_ISSET (0, rfds) && mac_wait_next_event (&e, sleep_time, false)) 1711 if (mac_wait_next_event (&e, sleep_time, false))
1750 return 1; 1712 err = noErr;
1751 1713 else
1752 return 0; 1714 err = -9875; /* eventLoopTimedOutErr */
1753#endif /* not TARGET_API_MAC_CARBON */ 1715#endif /* not TARGET_API_MAC_CARBON */
1754}
1755
1756
1757/* Called in sys_select to wait for an alarm signal to arrive. */
1758
1759int
1760pause ()
1761{
1762 EventRecord e;
1763 unsigned long tick;
1764
1765 if (!target_ticks) /* no alarm pending */
1766 return -1;
1767 1716
1768 if ((tick = TickCount ()) < target_ticks) 1717 if (FD_ISSET (0, rfds))
1769 WaitNextEvent (0, &e, target_ticks - tick, NULL); /* Accept no event; 1718 if (err == noErr)
1770 just wait. by T.I. */ 1719 return 1;
1720 else
1721 {
1722 FD_ZERO (rfds);
1723 return 0;
1724 }
1725 else
1726 if (err == noErr)
1727 {
1728 if (input_polling_used ())
1729 {
1730 /* It could be confusing if a real alarm arrives while
1731 processing the fake one. Turn it off and let the
1732 handler reset it. */
1733 extern void poll_for_input_1 P_ ((void));
1734 int old_poll_suppress_count = poll_suppress_count;
1735 poll_suppress_count = 1;
1736 poll_for_input_1 ();
1737 poll_suppress_count = old_poll_suppress_count;
1738 }
1739 errno = EINTR;
1740 return -1;
1741 }
1742 else
1743 return 0;
1744}
1771 1745
1772 target_ticks = 0;
1773 if (alarm_signal_func)
1774 (*alarm_signal_func)(SIGALRM);
1775 1746
1776 return 0; 1747/* Simulation of SIGALRM. The stub for function signal stores the
1777} 1748 signal handler function in alarm_signal_func if a SIGALRM is
1749 encountered. */
1778 1750
1751#include <signal.h>
1752#include "syssignal.h"
1779 1753
1780int 1754static TMTask mac_atimer_task;
1781alarm (int seconds)
1782{
1783 long remaining = target_ticks ? (TickCount () - target_ticks) / 60 : 0;
1784 1755
1785 target_ticks = seconds ? TickCount () + 60 * seconds : 0; 1756static QElemPtr mac_atimer_qlink = (QElemPtr) &mac_atimer_task;
1786 1757
1787 return (remaining < 0) ? 0 : (unsigned int) remaining; 1758static int signal_mask = 0;
1788}
1789 1759
1760#ifdef __MRC__
1761__sigfun alarm_signal_func = (__sigfun) 0;
1762#elif __MWERKS__
1763__signal_func_ptr alarm_signal_func = (__signal_func_ptr) 0;
1764#else /* not __MRC__ and not __MWERKS__ */
1765You lose!!!
1766#endif /* not __MRC__ and not __MWERKS__ */
1790 1767
1791#undef signal 1768#undef signal
1792#ifdef __MRC__ 1769#ifdef __MRC__
@@ -1819,6 +1796,128 @@ sys_signal (int signal_num, __signal_func_ptr signal_func)
1819} 1796}
1820 1797
1821 1798
1799static pascal void
1800mac_atimer_handler (qlink)
1801 TMTaskPtr qlink;
1802{
1803 if (alarm_signal_func)
1804 (alarm_signal_func) (SIGALRM);
1805}
1806
1807
1808static void
1809set_mac_atimer (count)
1810 long count;
1811{
1812 static TimerUPP mac_atimer_handlerUPP = NULL;
1813
1814 if (mac_atimer_handlerUPP == NULL)
1815 mac_atimer_handlerUPP = NewTimerUPP (mac_atimer_handler);
1816 mac_atimer_task.tmCount = 0;
1817 mac_atimer_task.tmAddr = mac_atimer_handlerUPP;
1818 mac_atimer_qlink = (QElemPtr) &mac_atimer_task;
1819 InsTime (mac_atimer_qlink);
1820 if (count)
1821 PrimeTime (mac_atimer_qlink, count);
1822}
1823
1824
1825int
1826remove_mac_atimer (remaining_count)
1827 long *remaining_count;
1828{
1829 if (mac_atimer_qlink)
1830 {
1831 RmvTime (mac_atimer_qlink);
1832 if (remaining_count)
1833 *remaining_count = mac_atimer_task.tmCount;
1834 mac_atimer_qlink = NULL;
1835
1836 return 0;
1837 }
1838 else
1839 return -1;
1840}
1841
1842
1843int
1844sigblock (int mask)
1845{
1846 int old_mask = signal_mask;
1847
1848 signal_mask |= mask;
1849
1850 if ((old_mask ^ signal_mask) & sigmask (SIGALRM))
1851 remove_mac_atimer (NULL);
1852
1853 return old_mask;
1854}
1855
1856
1857int
1858sigsetmask (int mask)
1859{
1860 int old_mask = signal_mask;
1861
1862 signal_mask = mask;
1863
1864 if ((old_mask ^ signal_mask) & sigmask (SIGALRM))
1865 if (signal_mask & sigmask (SIGALRM))
1866 remove_mac_atimer (NULL);
1867 else
1868 set_mac_atimer (mac_atimer_task.tmCount);
1869
1870 return old_mask;
1871}
1872
1873
1874int
1875alarm (int seconds)
1876{
1877 long remaining_count;
1878
1879 if (remove_mac_atimer (&remaining_count) == 0)
1880 {
1881 set_mac_atimer (seconds * 1000);
1882
1883 return remaining_count / 1000;
1884 }
1885 else
1886 {
1887 mac_atimer_task.tmCount = seconds * 1000;
1888
1889 return 0;
1890 }
1891}
1892
1893
1894int
1895setitimer (which, value, ovalue)
1896 int which;
1897 const struct itimerval *value;
1898 struct itimerval *ovalue;
1899{
1900 long remaining_count;
1901 long count = (EMACS_SECS (value->it_value) * 1000
1902 + (EMACS_USECS (value->it_value) + 999) / 1000);
1903
1904 if (remove_mac_atimer (&remaining_count) == 0)
1905 {
1906 if (ovalue)
1907 {
1908 bzero (ovalue, sizeof (*ovalue));
1909 EMACS_SET_SECS_USECS (ovalue->it_value, remaining_count / 1000,
1910 (remaining_count % 1000) * 1000);
1911 }
1912 set_mac_atimer (count);
1913 }
1914 else
1915 mac_atimer_task.tmCount = count;
1916
1917 return 0;
1918}
1919
1920
1822/* gettimeofday should return the amount of time (in a timeval 1921/* gettimeofday should return the amount of time (in a timeval
1823 structure) since midnight today. The toolbox function Microseconds 1922 structure) since midnight today. The toolbox function Microseconds
1824 returns the number of microseconds (in a UnsignedWide value) since 1923 returns the number of microseconds (in a UnsignedWide value) since
@@ -1946,35 +2045,6 @@ sys_time (time_t *timer)
1946} 2045}
1947 2046
1948 2047
1949/* MPW strftime broken for "%p" format */
1950#ifdef __MRC__
1951#undef strftime
1952#include <time.h>
1953size_t
1954sys_strftime (char * s, size_t maxsize, const char * format,
1955 const struct tm * timeptr)
1956{
1957 if (strcmp (format, "%p") == 0)
1958 {
1959 if (maxsize < 3)
1960 return 0;
1961 if (timeptr->tm_hour < 12)
1962 {
1963 strcpy (s, "AM");
1964 return 2;
1965 }
1966 else
1967 {
1968 strcpy (s, "PM");
1969 return 2;
1970 }
1971 }
1972 else
1973 return strftime (s, maxsize, format, timeptr);
1974}
1975#endif /* __MRC__ */
1976
1977
1978/* no subprocesses, empty wait */ 2048/* no subprocesses, empty wait */
1979 2049
1980int 2050int
@@ -1993,13 +2063,6 @@ croak (char *badfunc)
1993 2063
1994 2064
1995char * 2065char *
1996index (const char * str, int chr)
1997{
1998 return strchr (str, chr);
1999}
2000
2001
2002char *
2003mktemp (char *template) 2066mktemp (char *template)
2004{ 2067{
2005 int len, k; 2068 int len, k;
@@ -2187,20 +2250,6 @@ sys_subshell ()
2187} 2250}
2188 2251
2189 2252
2190int
2191sigsetmask (int x)
2192{
2193 return 0;
2194}
2195
2196
2197int
2198sigblock (int mask)
2199{
2200 return 0;
2201}
2202
2203
2204void 2253void
2205request_sigio (void) 2254request_sigio (void)
2206{ 2255{