Mercurial > emacs
comparison src/mac.c @ 89956:b9eee0a7bef5
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-25
Merge from emacs--cvs-trunk--0
Patches applied:
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-459
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-463
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-464
Update from CVS: lisp/progmodes/make-mode.el: Fix comments.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-465
Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Fri, 23 Jul 2004 04:30:44 +0000 |
parents | 68c22ea6027c 45d805d79d29 |
children | ff0e824afa37 |
comparison
equal
deleted
inserted
replaced
89955:7f8b53f94713 | 89956:b9eee0a7bef5 |
---|---|
2767 #undef select | 2767 #undef select |
2768 | 2768 |
2769 extern int inhibit_window_system; | 2769 extern int inhibit_window_system; |
2770 extern int noninteractive; | 2770 extern int noninteractive; |
2771 | 2771 |
2772 #include "blockinput.h" | |
2773 | |
2772 /* When Emacs is started from the Finder, SELECT always immediately | 2774 /* When Emacs is started from the Finder, SELECT always immediately |
2773 returns as if input is present when file descriptor 0 is polled for | 2775 returns as if input is present when file descriptor 0 is polled for |
2774 input. Strangely, when Emacs is run as a GUI application from the | 2776 input. Strangely, when Emacs is run as a GUI application from the |
2775 command line, it blocks in the same situation. This `wrapper' of | 2777 command line, it blocks in the same situation. This `wrapper' of |
2776 the system call SELECT corrects this discrepancy. */ | 2778 the system call SELECT corrects this discrepancy. */ |
2777 int | 2779 int |
2778 sys_select (n, rfds, wfds, efds, timeout) | 2780 sys_select (n, rfds, wfds, efds, timeout) |
2779 int n; | 2781 int n; |
2780 SELECT_TYPE *rfds; | 2782 SELECT_TYPE *rfds; |
2781 SELECT_TYPE *wfds; | 2783 SELECT_TYPE *wfds; |
2782 SELECT_TYPE *efds; | 2784 SELECT_TYPE *efds; |
2783 struct timeval *timeout; | 2785 struct timeval *timeout; |
2784 { | 2786 { |
2785 if (!inhibit_window_system && rfds && FD_ISSET (0, rfds)) | 2787 OSErr err; |
2786 return 1; | 2788 EMACS_TIME end_time, now, remaining_time; |
2787 else if (inhibit_window_system || noninteractive || | 2789 |
2788 (timeout && (EMACS_SECS(*timeout)==0) && | 2790 if (inhibit_window_system || noninteractive |
2789 (EMACS_USECS(*timeout)==0))) | 2791 || rfds == NULL || !FD_ISSET (0, rfds)) |
2790 return select(n, rfds, wfds, efds, timeout); | 2792 return select (n, rfds, wfds, efds, timeout); |
2791 else | 2793 |
2792 { | 2794 if (wfds == NULL && efds == NULL) |
2793 EMACS_TIME end_time, now; | 2795 { |
2794 | 2796 int i; |
2795 EMACS_GET_TIME (end_time); | 2797 |
2798 for (i = 1; i < n; i++) | |
2799 if (FD_ISSET (i, rfds)) | |
2800 break; | |
2801 if (i == n) | |
2802 { | |
2803 EventTimeout timeout_sec = | |
2804 (timeout | |
2805 ? (EMACS_SECS (*timeout) * kEventDurationSecond | |
2806 + EMACS_USECS (*timeout) * kEventDurationMicrosecond) | |
2807 : kEventDurationForever); | |
2808 | |
2809 BLOCK_INPUT; | |
2810 err = ReceiveNextEvent (0, NULL, timeout_sec, | |
2811 kEventLeaveInQueue, NULL); | |
2812 UNBLOCK_INPUT; | |
2813 if (err == noErr) | |
2814 { | |
2815 FD_ZERO (rfds); | |
2816 FD_SET (0, rfds); | |
2817 return 1; | |
2818 } | |
2819 else | |
2820 return 0; | |
2821 } | |
2822 } | |
2823 | |
2824 if (timeout) | |
2825 { | |
2826 remaining_time = *timeout; | |
2827 EMACS_GET_TIME (now); | |
2828 EMACS_ADD_TIME (end_time, now, remaining_time); | |
2829 } | |
2830 FD_CLR (0, rfds); | |
2831 do | |
2832 { | |
2833 EMACS_TIME select_timeout; | |
2834 SELECT_TYPE orfds = *rfds; | |
2835 int r; | |
2836 | |
2837 EMACS_SET_SECS_USECS (select_timeout, 0, 20000); | |
2838 | |
2839 if (timeout && EMACS_TIME_LT (remaining_time, select_timeout)) | |
2840 select_timeout = remaining_time; | |
2841 | |
2842 r = select (n, &orfds, wfds, efds, &select_timeout); | |
2843 BLOCK_INPUT; | |
2844 err = ReceiveNextEvent (0, NULL, kEventDurationNoWait, | |
2845 kEventLeaveInQueue, NULL); | |
2846 UNBLOCK_INPUT; | |
2847 if (r > 0) | |
2848 { | |
2849 *rfds = orfds; | |
2850 if (err == noErr) | |
2851 { | |
2852 FD_SET (0, rfds); | |
2853 r++; | |
2854 } | |
2855 return r; | |
2856 } | |
2857 else if (err == noErr) | |
2858 { | |
2859 FD_ZERO (rfds); | |
2860 FD_SET (0, rfds); | |
2861 return 1; | |
2862 } | |
2863 | |
2796 if (timeout) | 2864 if (timeout) |
2797 EMACS_ADD_TIME (end_time, end_time, *timeout); | |
2798 | |
2799 do | |
2800 { | 2865 { |
2801 int r; | |
2802 EMACS_TIME one_second; | |
2803 SELECT_TYPE orfds; | |
2804 | |
2805 FD_ZERO (&orfds); | |
2806 if (rfds) | |
2807 { | |
2808 orfds = *rfds; | |
2809 } | |
2810 | |
2811 EMACS_SET_SECS (one_second, 1); | |
2812 EMACS_SET_USECS (one_second, 0); | |
2813 | |
2814 if (timeout && EMACS_TIME_LT(*timeout, one_second)) | |
2815 one_second = *timeout; | |
2816 | |
2817 if ((r = select (n, &orfds, wfds, efds, &one_second)) > 0) | |
2818 { | |
2819 *rfds = orfds; | |
2820 return r; | |
2821 } | |
2822 | |
2823 mac_check_for_quit_char(); | |
2824 | |
2825 EMACS_GET_TIME (now); | 2866 EMACS_GET_TIME (now); |
2826 EMACS_SUB_TIME (now, end_time, now); | 2867 EMACS_SUB_TIME (remaining_time, end_time, now); |
2827 } | 2868 } |
2828 while (!timeout || !EMACS_TIME_NEG_P (now)); | 2869 } |
2829 | 2870 while (!timeout || EMACS_TIME_LT (now, end_time)); |
2830 return 0; | 2871 |
2831 } | 2872 return 0; |
2832 } | 2873 } |
2833 | |
2834 #undef read | |
2835 int sys_read (fds, buf, nbyte) | |
2836 int fds; | |
2837 char *buf; | |
2838 unsigned int nbyte; | |
2839 { | |
2840 SELECT_TYPE rfds; | |
2841 EMACS_TIME one_second; | |
2842 int r; | |
2843 | |
2844 /* Use select to block on IO while still checking for quit_char */ | |
2845 if (!inhibit_window_system && !noninteractive && | |
2846 ! (fcntl(fds, F_GETFL, 0) & O_NONBLOCK)) | |
2847 { | |
2848 FD_ZERO (&rfds); | |
2849 FD_SET (fds, &rfds); | |
2850 if (sys_select (fds+1, &rfds, 0, 0, NULL) < 0) | |
2851 return -1; | |
2852 } | |
2853 | |
2854 return read (fds, buf, nbyte); | |
2855 } | |
2856 | |
2857 | 2874 |
2858 /* Set up environment variables so that Emacs can correctly find its | 2875 /* Set up environment variables so that Emacs can correctly find its |
2859 support files when packaged as an application bundle. Directories | 2876 support files when packaged as an application bundle. Directories |
2860 placed in /usr/local/share/emacs/<emacs-version>/, /usr/local/bin, | 2877 placed in /usr/local/share/emacs/<emacs-version>/, /usr/local/bin, |
2861 and /usr/local/libexec/emacs/<emacs-version>/<system-configuration> | 2878 and /usr/local/libexec/emacs/<emacs-version>/<system-configuration> |