[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] Changes to emacs/src/mac.c
From: |
YAMAMOTO Mitsuharu |
Subject: |
[Emacs-diffs] Changes to emacs/src/mac.c |
Date: |
Fri, 13 May 2005 04:44:21 -0400 |
Index: emacs/src/mac.c
diff -c emacs/src/mac.c:1.36 emacs/src/mac.c:1.37
*** emacs/src/mac.c:1.36 Tue May 3 18:19:34 2005
--- emacs/src/mac.c Fri May 13 08:44:20 2005
***************
*** 1672,1708 ****
}
! long target_ticks = 0;
!
! #ifdef __MRC__
! __sigfun alarm_signal_func = (__sigfun) 0;
! #elif __MWERKS__
! __signal_func_ptr alarm_signal_func = (__signal_func_ptr) 0;
! #else /* not __MRC__ and not __MWERKS__ */
! You lose!!!
! #endif /* not __MRC__ and not __MWERKS__ */
!
!
! /* These functions simulate SIG_ALRM. The stub for function signal
! stores the signal handler function in alarm_signal_func if a
! SIG_ALRM is encountered. check_alarm is called in XTread_socket,
! which emacs calls periodically. A pending alarm is represented by
! a non-zero target_ticks value. check_alarm calls the handler
! function pointed to by alarm_signal_func if one has been set up and
! an alarm is pending. */
!
! void
! check_alarm ()
! {
! if (target_ticks && TickCount () > target_ticks)
! {
! target_ticks = 0;
! if (alarm_signal_func)
! (*alarm_signal_func)(SIGALRM);
! }
! }
!
!
extern Boolean mac_wait_next_event (EventRecord *, UInt32, Boolean);
int
--- 1672,1678 ----
}
! #include "keyboard.h"
extern Boolean mac_wait_next_event (EventRecord *, UInt32, Boolean);
int
***************
*** 1713,1737 ****
SELECT_TYPE *efds;
struct timeval *timeout;
{
- #if TARGET_API_MAC_CARBON
OSErr err;
EventTimeout timeout_sec =
(timeout
? (EMACS_SECS (*timeout) * kEventDurationSecond
+ EMACS_USECS (*timeout) * kEventDurationMicrosecond)
: kEventDurationForever);
! if (FD_ISSET (0, rfds))
! {
! BLOCK_INPUT;
! err = ReceiveNextEvent (0, NULL, timeout_sec, kEventLeaveInQueue, NULL);
! UNBLOCK_INPUT;
! if (err == noErr)
! return 1;
! else
! FD_ZERO (rfds);
! }
! return 0;
#else /* not TARGET_API_MAC_CARBON */
EventRecord e;
UInt32 sleep_time = EMACS_SECS (*timeout) * 60 +
--- 1683,1699 ----
SELECT_TYPE *efds;
struct timeval *timeout;
{
OSErr err;
+ #if TARGET_API_MAC_CARBON
EventTimeout timeout_sec =
(timeout
? (EMACS_SECS (*timeout) * kEventDurationSecond
+ EMACS_USECS (*timeout) * kEventDurationMicrosecond)
: kEventDurationForever);
! BLOCK_INPUT;
! err = ReceiveNextEvent (0, NULL, timeout_sec, kEventLeaveInQueue, NULL);
! UNBLOCK_INPUT;
#else /* not TARGET_API_MAC_CARBON */
EventRecord e;
UInt32 sleep_time = EMACS_SECS (*timeout) * 60 +
***************
*** 1746,1792 ****
read_avail_input which in turn calls XTread_socket to poll for
these events. Otherwise these never get processed except but a
very slow poll timer. */
! if (FD_ISSET (0, rfds) && mac_wait_next_event (&e, sleep_time, false))
! return 1;
!
! return 0;
#endif /* not TARGET_API_MAC_CARBON */
- }
-
-
- /* Called in sys_select to wait for an alarm signal to arrive. */
-
- int
- pause ()
- {
- EventRecord e;
- unsigned long tick;
-
- if (!target_ticks) /* no alarm pending */
- return -1;
! if ((tick = TickCount ()) < target_ticks)
! WaitNextEvent (0, &e, target_ticks - tick, NULL); /* Accept no event;
! just wait. by T.I. */
- target_ticks = 0;
- if (alarm_signal_func)
- (*alarm_signal_func)(SIGALRM);
! return 0;
! }
! int
! alarm (int seconds)
! {
! long remaining = target_ticks ? (TickCount () - target_ticks) / 60 : 0;
! target_ticks = seconds ? TickCount () + 60 * seconds : 0;
! return (remaining < 0) ? 0 : (unsigned int) remaining;
! }
#undef signal
#ifdef __MRC__
--- 1708,1769 ----
read_avail_input which in turn calls XTread_socket to poll for
these events. Otherwise these never get processed except but a
very slow poll timer. */
! if (mac_wait_next_event (&e, sleep_time, false))
! err = noErr;
! else
! err = -9875; /* eventLoopTimedOutErr */
#endif /* not TARGET_API_MAC_CARBON */
! if (FD_ISSET (0, rfds))
! if (err == noErr)
! return 1;
! else
! {
! FD_ZERO (rfds);
! return 0;
! }
! else
! if (err == noErr)
! {
! if (input_polling_used ())
! {
! /* It could be confusing if a real alarm arrives while
! processing the fake one. Turn it off and let the
! handler reset it. */
! extern void poll_for_input_1 P_ ((void));
! int old_poll_suppress_count = poll_suppress_count;
! poll_suppress_count = 1;
! poll_for_input_1 ();
! poll_suppress_count = old_poll_suppress_count;
! }
! errno = EINTR;
! return -1;
! }
! else
! return 0;
! }
! /* Simulation of SIGALRM. The stub for function signal stores the
! signal handler function in alarm_signal_func if a SIGALRM is
! encountered. */
+ #include <signal.h>
+ #include "syssignal.h"
! static TMTask mac_atimer_task;
! static QElemPtr mac_atimer_qlink = (QElemPtr) &mac_atimer_task;
! static int signal_mask = 0;
+ #ifdef __MRC__
+ __sigfun alarm_signal_func = (__sigfun) 0;
+ #elif __MWERKS__
+ __signal_func_ptr alarm_signal_func = (__signal_func_ptr) 0;
+ #else /* not __MRC__ and not __MWERKS__ */
+ You lose!!!
+ #endif /* not __MRC__ and not __MWERKS__ */
#undef signal
#ifdef __MRC__
***************
*** 1819,1824 ****
--- 1796,1923 ----
}
+ static pascal void
+ mac_atimer_handler (qlink)
+ TMTaskPtr qlink;
+ {
+ if (alarm_signal_func)
+ (alarm_signal_func) (SIGALRM);
+ }
+
+
+ static void
+ set_mac_atimer (count)
+ long count;
+ {
+ static TimerUPP mac_atimer_handlerUPP = NULL;
+
+ if (mac_atimer_handlerUPP == NULL)
+ mac_atimer_handlerUPP = NewTimerUPP (mac_atimer_handler);
+ mac_atimer_task.tmCount = 0;
+ mac_atimer_task.tmAddr = mac_atimer_handlerUPP;
+ mac_atimer_qlink = (QElemPtr) &mac_atimer_task;
+ InsTime (mac_atimer_qlink);
+ if (count)
+ PrimeTime (mac_atimer_qlink, count);
+ }
+
+
+ int
+ remove_mac_atimer (remaining_count)
+ long *remaining_count;
+ {
+ if (mac_atimer_qlink)
+ {
+ RmvTime (mac_atimer_qlink);
+ if (remaining_count)
+ *remaining_count = mac_atimer_task.tmCount;
+ mac_atimer_qlink = NULL;
+
+ return 0;
+ }
+ else
+ return -1;
+ }
+
+
+ int
+ sigblock (int mask)
+ {
+ int old_mask = signal_mask;
+
+ signal_mask |= mask;
+
+ if ((old_mask ^ signal_mask) & sigmask (SIGALRM))
+ remove_mac_atimer (NULL);
+
+ return old_mask;
+ }
+
+
+ int
+ sigsetmask (int mask)
+ {
+ int old_mask = signal_mask;
+
+ signal_mask = mask;
+
+ if ((old_mask ^ signal_mask) & sigmask (SIGALRM))
+ if (signal_mask & sigmask (SIGALRM))
+ remove_mac_atimer (NULL);
+ else
+ set_mac_atimer (mac_atimer_task.tmCount);
+
+ return old_mask;
+ }
+
+
+ int
+ alarm (int seconds)
+ {
+ long remaining_count;
+
+ if (remove_mac_atimer (&remaining_count) == 0)
+ {
+ set_mac_atimer (seconds * 1000);
+
+ return remaining_count / 1000;
+ }
+ else
+ {
+ mac_atimer_task.tmCount = seconds * 1000;
+
+ return 0;
+ }
+ }
+
+
+ int
+ setitimer (which, value, ovalue)
+ int which;
+ const struct itimerval *value;
+ struct itimerval *ovalue;
+ {
+ long remaining_count;
+ long count = (EMACS_SECS (value->it_value) * 1000
+ + (EMACS_USECS (value->it_value) + 999) / 1000);
+
+ if (remove_mac_atimer (&remaining_count) == 0)
+ {
+ if (ovalue)
+ {
+ bzero (ovalue, sizeof (*ovalue));
+ EMACS_SET_SECS_USECS (ovalue->it_value, remaining_count / 1000,
+ (remaining_count % 1000) * 1000);
+ }
+ set_mac_atimer (count);
+ }
+ else
+ mac_atimer_task.tmCount = count;
+
+ return 0;
+ }
+
+
/* gettimeofday should return the amount of time (in a timeval
structure) since midnight today. The toolbox function Microseconds
returns the number of microseconds (in a UnsignedWide value) since
***************
*** 1946,1980 ****
}
- /* MPW strftime broken for "%p" format */
- #ifdef __MRC__
- #undef strftime
- #include <time.h>
- size_t
- sys_strftime (char * s, size_t maxsize, const char * format,
- const struct tm * timeptr)
- {
- if (strcmp (format, "%p") == 0)
- {
- if (maxsize < 3)
- return 0;
- if (timeptr->tm_hour < 12)
- {
- strcpy (s, "AM");
- return 2;
- }
- else
- {
- strcpy (s, "PM");
- return 2;
- }
- }
- else
- return strftime (s, maxsize, format, timeptr);
- }
- #endif /* __MRC__ */
-
-
/* no subprocesses, empty wait */
int
--- 2045,2050 ----
***************
*** 1993,2005 ****
char *
- index (const char * str, int chr)
- {
- return strchr (str, chr);
- }
-
-
- char *
mktemp (char *template)
{
int len, k;
--- 2063,2068 ----
***************
*** 2187,2206 ****
}
- int
- sigsetmask (int x)
- {
- return 0;
- }
-
-
- int
- sigblock (int mask)
- {
- return 0;
- }
-
-
void
request_sigio (void)
{
--- 2250,2255 ----